question

JustinSmith-1044 avatar image
0 Votes"
JustinSmith-1044 asked IanXue-MSFT edited

Mass Modifying Home Folder

Currently working on a project to migrate users over to a new file server. The new server will have a similar name, just one character different. Every user has a personal share mapped using the home folder in Active Directory with a naming convention of their last name and the first letter of their first name. I have the following put together, but I cant figure out how to get the individual paths to set correctly

Get-ADUser -SearchBase "$ou" -Filter * | Set-ADUser -HomeDirectory:"\\$fileserver(LastF Goes Here)\"

Any assistance would be greatly appreciated. My knowledge of how to Powershell drops off a cliff when it gets more complex than a piped command.

windows-server-powershellwindows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT edited

Hi,

If the first name and the last name are stored in the properties GivenName and Surname you can do it like below

 Get-ADUser -SearchBase $ou -Filter * | ForEach-Object {
      Set-ADUser $_ -HomeDirectory "\\$fileserver\$($_.Surname)$($_.GivenName[0])"
 }

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.