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