Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, December 19, 2014 8:16 AM
Hi,
Before we provision our desktopservers we need to delete all userprofiles from the registry except the following usernames: Administrator and CTX_Streaminig.
This is what i got now:
$REGPROF=’REGISTRY::HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList’
$PROFLIST=GET-CHILDITEM $REGPROF
FOREACH ( $ITEM in $PROFLIST )
{
$userid=(get-itemproperty registry::$item).ProfileImagePath
write-host @userid
if ($userid -notlike @("*administrator*","*Ctx_StreamingSvc","*NetworkService*","*Localservice*","*systemprofile*")) { $userid; remove-item registry::$item }
}
Why isn't it working, my administrator account is deleted and networkservice, localservice and systemprofiles also?
write-host @ userid shows:
C:\Windows\system32\config\systemprofile
C : \ W i n d o w s \ S e r v i c e P r o f i l e s \ L o c a l S e r v i c e
etc. There are spaces in between?
Please help me out here....
Thanks!
All replies (6)
Friday, December 19, 2014 11:03 AM ✅Answered | 1 vote
Be careful:
Get-ChildItem ’HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList’ |
ForEach-Object{
$profilepath=$_.GetValue('ProfileImagePath')
if($profilepath -notmatch 'administrator|Ctx_StreamingSvc|NetworkService|Localservice|systemprofile'){
Write-Host "Removing item: $profilepath" -ForegroundColor green
Remove-Item $_.PSPath -Whatif
}else{
Write-Host "Skipping item:$profilepath" -Fore blue -Back white
}
}
¯\(ツ)_/¯
Friday, December 19, 2014 10:45 AM | 1 vote
This does not delete the profile. It deletes only the registry reference. It willbe replaced the next time the system is started. TOremove prfiles you will need ti use WMI. WMI will skip critical profiles.
If you are trying to fix hung profiles you may need to do this differently.
¯\(ツ)_/¯
Monday, December 22, 2014 3:22 PM
Thank you for your reply!
I will test this tomorrow and keep you updated!
Tuesday, December 23, 2014 2:30 PM
Exactly what it need to do! Thanks a lot!
Monday, June 15, 2015 8:58 PM
This was an awesome help thanks! For deleting the profile folders I did something pretty simple without WMI commands and just combined it with your script. The variable $Objectpath isn't really necessary since it's an unchanging short path, but it makes it easier for me to modify the script.
$objectpath = "C:\Users\"
Remove-Item -path "$objectpath*" -Exclude Administrator, Default, Public -Confirm
Get-Childitem -path "$objectpath*" | Out-Gridview -Title "REMAINING USER ACCOUNTS ON YOUR COMPUTER"
I do have a question, I can display the results for the folders as you can see, but how can I export the results from your script?
Monday, June 15, 2015 9:07 PM
This topic is closed and has been for some time. If you have a ne question please start you own topic and someone will try to help you.
If you proceed to delete profiles the way you are you will absolutely crash some systems. DO NOT DO IT your way.
\(ツ)_/