On Windows workstations and servers, particularly on RDS (Remote Desktop Services) servers, there’s a common want to take away outdated (unused) consumer profiles from C:Users. The essential downside of any Remote Desktop server is the fixed development the scale of consumer profile directories on an area drive. It is partially solved by enabling quotas on the utmost consumer profiles dimension (with FSRM or ). However, if there are plenty of terminal server customers, with time the C:Users listing will accumulate an enormous variety of directories with consumer profiles that aren’t longer wanted.
How to Delete a User Profile Manually in Windows?
Many novice Windows admins strive to manually delete a consumer profile folder from C:Users. You can do it if after manually deleting the folder, you’ll delete the consumer profile part with the hyperlink to this folder from the registry key HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NT CurrentVersionProfileRecord.
The appropriate manner to manually delete a consumer profile in Windows is to open System Properties, go to Advanced System Settings -> User Profiles -> Settings, choose a consumer within the checklist (the Size column proven the scale of the profile on the native drive) and click on the Delete button.
But this can be a guide technique, and it’s your decision to automate it.
GPO: Delete User Profiles Older Than a Specified Number Days
In Windows, there’s a built-in Group Policy to robotically delete consumer profiles older than xx days. You can discover the coverage Delete consumer profiles older than a specified quantity days on system restart within the GPO part Computer Configuration -> Administrative Templates -> System -> User Profiles. You can allow this coverage within the Local Group Policy Editor (gpedit.msc) or utilizing area insurance policies in GPMC.msc.
Enable the coverage and specify the variety of days a consumer profile is taken into account energetic. When this era is over, Windows consumer profile service will robotically delete the profile on the subsequent restart. It is advisable to specify the interval of 45-90 days right here.
The essential troubles related to this automated technique of profile elimination is ready for the server restart and non-selectivity (you can not prohibit deleting sure consumer profiles like native accounts, administrative accounts, and many others.). Also, this coverage could not work if some third-party software program (most frequently it’s an antivirus) accesses NTUSER.DAT file in consumer profiles and updates the date of final use.
PowerShell Script to Delete Old User Profiles in Windows
Instead of utilizing the automated cleanup profile coverage described above, you should use a easy PowerShell script to discover and take away profiles of or inactive customers.
First of all, let’s strive to rely the scale of all consumer profil folders in C:Users utilizing a easy script from the article :
gci -force 'C:Users'-ErrorAction SilentlyContinue | ? | % %
$_.fullname, ' GB' -f ($len / 1Gb)
$sum = $sum + $len
“Total dimension of profiles”,' GB' -f ($sum / 1Gb)
The complete dimension of all consumer profiles in C:Users is 31,5 GB.
Let’s show the checklist of customers, whose profiles has not been used for greater than 60 days. To discover them, you should use the worth within the LastUseTime discipline of the profile.
Get-WMIObject -class Win32_UserProfile | Where | Measure-Object
It turned out that I had 127 inactive consumer accounts on my RDS host (with a profiles complete dimension of about 18 GB).
To take away all these profiles, it’s sufficient to redirect the consumer checklist to the Remove-WmiObject command (prior to operating the script, it is strongly recommended to double-check its output utilizing the –WhatIf parameter):
Get-WMIObject -class Win32_UserProfile | Where | Remove-WmiObject –WhatIf
In order not to delete profiles of some customers, like System and Network Service accounts, a native administrator account, accounts of customers having energetic periods, account exception checklist), you’ll be able to modify the script as follows:
#The checklist of accounts, which profiles should not be deleted
$LocalProfiles=Get-WMIObject -class Win32_UserProfile | Where
foreach ($LocalProfile in $LocalProfiles)
You can at shutdown or with a .
Before configuring automated deletion of profiles, it is strongly recommended to check the script in your surroundings!
You can modify the script to robotically take away all consumer profiles (for instance, DisabledUsers group):
$customers = Get-ADGroupMember -Identity DisabledUsers | Foreach
$profiles = Get-WmiObject Win32_UserProfile
$profiles | Where | Foreach