![]() $compArray = -Path "\\path\to\computers.txt" | ForEach-Object #This Example Utilizes Windows Workflow Foundation Technology, Available in PowerShell V3 and Above #Invoke Remove-UserProfile on Many Remote Computers, Passing in Arguments ![]() Invoke-Command -ComputerName "GWS-F20" -ScriptBlock $scriptBlock #Invoke Remove-UserProfile on a Remote Computer Remove-UserProfile -Exclude "desktopuser") -Director圜leanup #Remove all non-active and non-system designated user profiles except "labadmin" and "desktopuser", and remove additional non-profile files/folders within C:\Users as well. Remove-UserProfile -Before (Get-Date).AddMonths(-1) -Verbose #Remove all non-active and non-system designated user profiles not used within the past month, displaying verbose output as well. #Remove all non-active and non-system designated user profiles from the local computer. This PowerShell Script can solve this problem IF = GOTO REGCHECKV2įOR /f "tokens=3" %%k in ('reg query %1 /v ProfileImagePath') DO SET USERREGPATHV=%%kįOR /f "tokens=3 delims=\" %%l in ('echo %USERREGPATHV%') DO SET USERREGV=%%lįOR /f "tokens=1 delims=." %%m IN ('echo %USERREGV%') DO SET USERREGPARSEV=%%mĮCHO %USERPRESERVE%|find /I "%USERREGPARSEV%" > NULĮcho Total Profiles Cleaned is %profiles% IF EXIST "C:\Users\%USERREG%" GOTO RETRYCLEAN2įOR /f "tokens=*" %%g IN ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist"^|find /i "s-1-5-21"') DO CALL :REGCHECKV "%%g"įOR /f "tokens=3,4" %%h in ('reg query %1 /v ProfileImagePath') DO SET USERREGPATHV=%%h %%iįOR /f "tokens=2" %%j in ('echo %USERREGPATHV%') DO SET SPACECHECKV=%%j IF EXIST "C:\Users\%USERREG%" GOTO RETRYCLEAN1ĮCHO Retrying clean of user profile %USERREG% Rmdir /s "C:\Users\%USERREG%" /s /q > NULĮCHO Cleaning user registry for %USERREG% Set userpreserve="All Users,Default,Default User,Public,cgb30,cgb30-lib,colette,colette-lib,ajw57,ajw57-lib,ad-lib,wilshire-lib,wilshire,setup"įOR /f "tokens=*" %%a IN ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist"^|find /i "s-1-5-21"') DO CALL :REGCHECK "%%a"įOR /f "tokens=3,4" %%b in ('reg query %1 /v ProfileImagePath') DO SET USERREGPATH=%%b %%cįOR /f "tokens=2" %%d in ('echo %USERREGPATH%') DO SET SPACECHECK=%%dįOR /f "tokens=3" %%g in ('reg query %1 /v ProfileImagePath') DO SET USERREGPATH=%%gįOR /f "tokens=3 delims=\" %%e in ('echo %USERREGPATH%') DO SET USERREG=%%eįOR /f "tokens=1 delims=." %%f IN ('echo %USERREG%') DO SET USERREGPARSE=%%fĮCHO %USERPRESERVE%|find /I "%USERREGPARSE%" > NULĮCHO %userdelete%|find /I "%USERREGPARSE%" > NUL If UserDeleteJoin_Skip="" (set userdelete=%1
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |