我使用以下代码超过16个月,所有突然的$ ldapresult都是空的。
Import-module ActiveDirectory
if((Get-PSSnapin | Where {$_.Name -eq “Microsoft.SharePoint.PowerShell”}) -eq $null) {
}
$SearchBase = "OU=Active-Users,DC=Rubber,DC=Maid"
$LdapServer = "YYYDC12XYZ.Rubber.Maid"
$ADAccount = "sjones"
Get-ADDomainController -server $ldapserver
$LDAPResult = Get-ADUser -SearchBase $searchbase -SearchScope 'subtree' -Server $ldapserver -filter "Account -like '*$ADAccount*'" -Properties * | Select -Property AccountExpirationDate, userAccountControl
$pair1, $pair2 = $LDAPResult -replace '^@{|}$' -split '; '
$null, $AccountExpirationDate = $pair1 -split '=', 2
$null, $userAccountControl = $pair2 -split '=', 2
write-host $ADAccount $AccountExpirationDate $userAccountControl -foregroundcolor "green"
write-host $LDAPResult
所以我运行了以下命令,确定它带来了sjones的所有数据。知道为什么上面的代码不再起作用了吗?
Get-ADUser $ADAccount -Properties * | Select *
答案 0 :(得分:0)
过滤器中的属性不正确-filter "Account -like '*$ADAccount*'"
将过滤器中的“帐户”替换为“SamAccountName”,如下所示:
-Filter "SamAccountName -like '*$ADAccount*'"