简体   繁体   中英

Get-ADUSER related issue

I was building this script to compare the samaccountname with the homefolder name in the homedirectory attribute (the last in the path) & if they r not same - then just rename the homefolder and update the homedirectory attribute.

It would be something like this I suppose -

Get-aduser -filter * | foreach {

$_.samaccountname

dont know how to capture homedirectory and then cut it to get what i want..

so help pls!

The following should work

$users = (Get-ADUser -filter * -properties "HomeDirectory")
foreach ($user in $users)
{
    $HomeFolder = "UNCFolderPath" + $user.SamAccountName
    if ($user.homedirectory -notmatch $user.SamAccountname)
    {
        Set-ADUser $user.SamAccountName -HomeDirectory $HomeFolder
    }
    else
    {
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM