Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Description / Function
- # This script will change the Home Folder (Connect:) in the AD User properties
- # Used for migration, this script will check the existing path to see if it contains the old file server ($source)
- # If old file server is found, it will rename to new file server ($destination)
- # eg. \\5555FS03\Staff$\08123456 to \\5555FS01\Staff$\08123456
- #Note - This script will ONLY replace part of a string. eg. 5555FS01 to 5555FS03
- #and leaves everything else in-tact.
- Import-Module ActiveDirectory
- # EDIT BELOW #
- $OU = "OU=test,OU=Staff,OU=Users,OU=ABC,DC=internal,DC=domain-name,DC=wan"
- $source = "5555FS03"
- $destination = "5555FS01"
- # EDIT ABOVE #
- $users = Get-ADUser -Filter * -Properties HomeDirectory -SearchBase $OU
- foreach($user in $users) {
- $oldDir = $user.HomeDirectory
- $newDir = $user.HomeDirectory -replace [Regex]::Escape("$source"), "$destination"
- Set-ADUser $user -HomeDirectory $newDir
- if($oldDir -Ne $newDir) {
- Write-Host $user.Name
- Write-Host "OldDir: $oldDir"
- Write-Host "NewDir: $newDir"
- Write-Host ""
- } else {
- Write-Host $user.Name + ": Nothing to do"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment