I would like to set the home directory based on a csv file containing a list of usernames.
I imagine there is a combination of get-user, set-user, and foreach commands that give the correct updates. Here is the code I am using but I'm unable to make the logical jump to piping this output to a Set-ADUser command which sets the home directory.
function ConvertUser($user)
{
$search = New-Object DirectoryServices.DirectorySearcher([ADSI]“”)
$search.filter = “(&(objectClass=user)(displayName=$user))”
$results = $search.Findall()
foreach($result in $results){
$userEntry = $result.GetDirectoryEntry()
Write-Output($userEntry.sAMAccountName)
}
}
function ConvertUsers
{
process{
foreach($user In $_){
ConvertUser($user)
}
}
}
Get-Content ".Users.txt" | ConvertUsers
I'm sure I'm missing something simple but alas I am a Powershell newb.
Edit: I would like to have the output from ConverUsers which is the username and then pipe that to the set-aduser command. Any time I try and pipe it to set-aduser I either get syntax errors, empty pipe, or the wrong data output.