Core Facility Bioimaging
print

Links and Functions

Breadcrumb Navigation


Content

Clean-up Tools

Page Version: 2026-08-13

See the chapter on downloading and running scripts on this web page: Moving Users from old to new microscope computer. You might want to copy scripts into a folder C:\scripts. 

Deleting old user accounts

Over time, on every microscope computer user accounts accumulate, since users typically do not tell the Core Facility that they leave the institution. These accounts should be deleted and the script DeleteOldUserAccounts.ps1 does this: it permanently deletes an account and its entire Windows profile folder in C:\Users, all files inside, plus the associated registry entry. This cannot be undone, and all the data in the user folder in C:\Users will be gone. Note that it does not delete anything outside C:\Users. Data the user may have stored elsewhere, such as E:\data, must be deleted manually.

Started in an admin PowerShell, the script DeleteOldUserAccounts.ps1 will do the following:

  • Asks for a cut-off date (format yyyy-mm-dd). Only accounts that last logged on before this date — or never logged on at all — are shown; you can abort here instead of entering a date.
  • Shows a table of all accounts matching that criterion, sorted oldest-first (with anyone who never logged on listed at the very top), including their name, full name (if set), and last logon date.
  • Warns clearly that deletion is permanent, then asks whether to go through the list one by one, or abort without changing anything.
  • For each account in turn, shows that account's row again and asks whether to delete it, keep it, or stop reviewing the remaining accounts (anything already deleted up to that point stays deleted). There is no option to delete all accounts at once — each one requires an individual decision.
  • When an account is deleted, prints a confirmation (including the full name, if available) and a reminder that this is a good time to also delete that user's data folder elsewhere (on other partitions), since the script does not do this itself.
  • Records every deleted account in DeletedUsers.csv (in the same folder as the script by default), with their last logon date and the date/time of deletion.
  • At the end, shows a summary in the console: how many accounts were deleted, how many were kept, and how many ran into errors.

Deleting empty folders on the data partition

Sometimes users delete all their data on the data partition (e.g. E:\), but not their folders. While this is usually ok, it might get annoying if you need to go through the data partition to delete old files. DeleteEmptyFolders.ps1 can help with this. It does the following when started in an admin PowerShell:

  • Asks which drive to process, e, f, or whatever. Gives error if C is selected. 
  • For every top level folder in this partition, checks whether it contains any data, directly or in subfolders. Hidden files (such as desktop.ini) are ignored. Empty subfolders also do not count. 
  • If no empty folders are found, says so and stops.
  • Otherwise, shows a table of every empty folder found, with its name and last-changed date.
  • Asks whether to (D)elete them or (A)bort.
  • If deleting, removes each one (and everything inside it, including hidden files and subfolders) and reports success or error per folder.
  • Ends with a summary: how many folders were deleted, and how many errors occurred.

Deleting temporary user files

Temporary files of users, such as browser caches, Recycle-bin files, etc. may clog up the system partition C:\. The script ShutdownCleanup.ps1 is best installed as a shut-down routine, so that such files are continuously removed. It also can be run individually in a PowerShell with admin rights. It is described in more details towards the end of the page Routine for a new microscope computer (Win 11).

Increase free space on C:\

The script FreeSpaceOnC.ps1 deletes large (image) files on the system partition C:\, where they are not supposed to be according to local policy. Data should only go to data partitions. It also deletes some other files. For a full description also see towards the end of Routine for a new microscope computer (Win 11).


Service