Guest User

Untitled

a guest
Apr 8th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #Description / Function
  2. # This script will change the Home Folder (Connect:) in the AD User properties
  3. # Used for migration, this script will check the existing path to see if it contains the old file server ($source)
  4. # If old file server is found, it will rename to new file server ($destination)
  5. # eg. \\5555FS03\Staff$\08123456 to \\5555FS01\Staff$\08123456
  6. #Note - This script will ONLY replace part of a string. eg. 5555FS01 to 5555FS03
  7. #and leaves everything else in-tact.
  8.  
  9. Import-Module ActiveDirectory
  10.  
  11. # EDIT BELOW #
  12. $OU = "OU=test,OU=Staff,OU=Users,OU=ABC,DC=internal,DC=domain-name,DC=wan"
  13. $source = "5555FS03"
  14. $destination = "5555FS01"
  15. # EDIT ABOVE #
  16.  
  17. $users = Get-ADUser -Filter * -Properties HomeDirectory -SearchBase $OU
  18.  
  19. foreach($user in $users) {
  20.  
  21. $oldDir = $user.HomeDirectory
  22. $newDir = $user.HomeDirectory -replace [Regex]::Escape("$source"), "$destination"
  23. Set-ADUser $user -HomeDirectory $newDir
  24.  
  25. if($oldDir -Ne $newDir) {
  26. Write-Host $user.Name
  27. Write-Host "OldDir: $oldDir"
  28. Write-Host "NewDir: $newDir"
  29. Write-Host ""
  30. } else {
  31. Write-Host $user.Name + ": Nothing to do"
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment