powershell - Rename folders in file share -
the script comparing folder names in share store user profiles in ad , seeing ones disabled or don't exist , counting them. want take list , rename user folders aren't in ad .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 after:
$delusercount = $delusercount + 1
insert:
rename-item "\\kiewitplaza\vdi\appsense_profiles\$name" ` "\\kiewitplaza\vdi\appsense_profiles\$name.old"
update:
you want insert after foreach
statement:
if($name.endswith(".old")) { continue }
this prevent renamed folders being processed , renamed again ending example folder user bob
becoming bob.old
potentially bob.old.old
bob.old.old.old
, on.
Comments
Post a Comment