powershell 新手,我不知道为什么输出文件中的 SamAccountName 列是空的。而 IsDisabled 列具有帐户状态结果。
Import-Csv $filename | Foreach-Object{
$user = ([ADSISEARCHER]"(samaccountname=$($_.SamAccountName))").FindOne()
if($user)
{
New-Object -TypeName PSObject -Property @{
SamAccountName = $user.SamAccountName
IsDisabled = $user.GetDirectoryEntry().InvokeGet('AccountDisabled')
}
}
else
{
Write-Warning "Can't find user '$($_.SamAccountName)'"
}
} | Export-Csv $filename