The script is comparing folder names in a share where we store user profiles to those in AD and seeing which ones are disabled or don't exist and counting them. I now want to take that list and rename all the user folders that aren't in AD to .old.
$delusercount = 0
$usernotfoundcount = 0
$foldernames = (Get-ChildItem \\kiewitplaza\vdi\appsense_profiles).Name
foreach($name in $foldernames)
{
try
{
$user = get-aduser $name -properties enabled
if($user.enabled -eq $false)
{
$delusercount = $delusercount + 1
}
}
catch
{
$usernotfoundcount = $usernotfoundcount + 1
}
}
write-host "User disabled in AD count " $delusercount
write-host "User ID NotFound in AD count " $usernotfoundcount
How about just after:
Insert:
Update:
You probably also want to insert just after your
foreachstatement:This will prevent previously renamed folders from being processed and renamed again thus ending up for example with the folder for user
BobbecomingBob.oldthen potentiallyBob.old.oldthenBob.old.old.oldand so on.