简体   繁体   English

Get-ADUSER相关问题

[英]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. 我正在构建此脚本,以比较samaccountnamehomedirectory 属性(路径中的最后一个)中homefolder名称,如果它们不相同,则只需重命名homefolder并更新homedirectory属性。

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
    {
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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