[英]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.