与 Get-ADUser 相关的查询

Query Related to Get-ADUser

创建 powershell 脚本以搜索整个 AD 用户以获取未在其属性中分配主目录或主驱动器的用户列表并将其 samaccountname 保存在变量堆栈中的最佳方法是什么并通过遍历每个名​​称 - 创建其主驱动器文件夹

我想应该是这样的

 $c = get-ADUser -filter * -searchbase -properties 
    foreach($b in $c)
    {
    New-item -path
    }

有人可以帮忙吗?

你可以使用这个:

$SAMs = Get-ADUser -filter * -Properties ProfilePath | ? {$_.ProfilePath -eq $Null} | Select SamaccountName

foreach ($SAM in $SAMs)
{
$NewDir = New-Item $SAM -Type Directory -Path "ChooseYourPath" ## Create the Folder in desired path
Set-ADUser $SAM -ProfilePath $NewDir.FullName ## Set the AD User Account ProfilePath Property with the New Folder
}

使用LDAPFilter参数查找所有主目录属性为空的用户:

Get-ADUser -LDAPFilter "(!(profilePath=*))" | ForEach-Object {
    $Username = $_.SAMAccountName
    $NewHomeDir = New-Item -Path "\homedir\root\path" -ItemType Directory -Name $Username
    if($?){
        Set-ADUser $_ -ProfilePath $NewHomeDir.FullName
    }
}