Mass Modifying Home Folder

Justin Smith 1 Reputation point
2021-03-25T13:48:54.153+00:00

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.

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,836 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,491 Reputation points Microsoft Vendor
    2021-03-26T05:57:13.59+00:00

    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.

    0 comments No comments