Remove HKCU registry entries of multiple users

$Users = (Get-ChildItem -path c:\users).name
foreach ($User in $Users) {
    reg load "hku\$User" "C:\Users\$User\NTUSER.DAT"
    # Do what you need with "hkey_users\$user" here which links to that user HKU
    # Example: reg add "hkey_users\$User\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People" /v "PeopleBand" /t "REG_DWORD" /d "0" /f
    REG DELETE "hkey_users\$User\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OneDrive" /f
    REG DELETE "hkey_users\$User\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "com.squirrel.Teams.Teams" /f
    reg unload "hku\$User"
}

Note: Current users logged on the system will be not affected because the ntuser.dat file is locked by the system.

Leave a Reply

Your email address will not be published.