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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -