Get-QADComputer -LdapFilter 和变量

Get-QADComputer -LdapFilter 和变量

我可以将 LdapFilter 中的变量与 Get-QADComputer 一起使用吗?即:

$31DaysAgo = (Get-Date).AddDays(-31)

$ft = $31DaysAgo.ToFileTime()

$StComps = Get-QADComputer -SizeLimit 0 -IncludeAllProperties -SearchRoot `
'DC=MY,DC=DOMAIN,DC=LOCAL' -LdapFilter '(&(objectcategory=computer) `
(pwdLastSet<=$ft)(|(operatingsystem=Windows 2000 Professional) `
(operatingSystem=Windows XP*)(operatingSystem=Windows 7*) `
(operatingSystem=Windows Vista*)(operatingsystem=Windows 2000 Server) `
(operatingsystem=Windows Server*)))'

如果没有,我还能如何过滤掉 pwdLastSet 过滤器?我应该在管道之后再执行此操作吗?即:

$StComps = Get-QADComputer -SizeLimit 0 -IncludeAllProperties -SearchRoot `
'DC=MY,DC=DOMAIN,DC=LOCAL' -LdapFilter '(&(objectcategory=computer) `
(|(operatingsystem=Windows2000 Professional)(operatingSystem=Windows XP*) `
(operatingSystem=Windows7*)(operatingSystem=Windows Vista*) `
(operatingsystem=Windows 2000 Server)(operatingsystem=Windows Server*)))' `
| Where {$_.pwdLastSet -gt $ft}

甚至

| Where {$_.LastLogonTimeStamp -gt $ft}

我知道这会比较慢,但如果必须的话,我会选择这条路。

此外,如果有人知道如何计算代码片段运行所需的时间,那将不胜感激=) ktxbye

谢谢,-dboftlp

答案1

您的第一个查询应该可以工作,但是您需要将 LdapFilter 放在双引号中"- PowerShell 不会扩展单引号内的变量。

$StComps = Get-QADComputer -SizeLimit 0 -IncludeAllProperties -SearchRoot `
'DC=MY,DC=DOMAIN,DC=LOCAL' -LdapFilter "(&(objectcategory=computer) `
(pwdLastSet<=$ft)(|(operatingsystem=Windows 2000 Professional) `
(operatingSystem=Windows XP*)(operatingSystem=Windows 7*) `
(operatingSystem=Windows Vista*)(operatingsystem=Windows 2000 Server) `
(operatingsystem=Windows Server*)))"

相关内容