2015-03-19 21 views
-1

您是否知道如果可能以及如何在不安裝ActiveDirectory模塊的情況下檢查用戶是否鎖定在ActiveDirectory中?在機器上安裝東西是有限制的,我想知道是否可以使用另一個函數,與Get-ADUser不同。 謝謝!PowerShell在ActiveDirectory中檢查鎖定的用戶

+0

使用ADSI提供商。不是重複的,而是參考:http://stackoverflow.com/questions/2585205/unlocking-locked-out-accounts-using-powershell-not-with-quest-ad-cmdlets – Matt 2015-03-19 11:16:08

回答

1

是這樣的:

$sAMAccountName = "testuser" 
$ADS_UF_LOCKOUT = 16  
$Attribute = "msds-user-account-control-computed"  
$ADSearcher = New-Object System.DirectoryServices.DirectorySearcher 
$ADSearcher.PageSize = 1000 
$ADSearcher.Filter = "samaccountname=$sAMAccountName" 
$User = $ADSearcher.FindOne()  
$MyUser = $User.GetDirectoryEntry() 
$MyUser.RefreshCache($Attribute)  
$UserAccountFlag = $MyUser.Properties[$Attribute].Value  
if ($UserAccountFlag -band $ADS_UF_LOCKOUT) 
{ 
Write-host "Account $sAMAccountName is locked" 
} 
else 
{ 
Write-host "Account $sAMAccountName isn't locked" 
} 
+0

非常感謝!這對我來說非常合適! – 2015-04-03 12:44:24

相關問題