我可以在 Get-QADComputer 和 LdapFilter 中使用变量吗?IE:
$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 过滤器?我应该在管道中完成它吗?IE:
$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
您的第一个查询应该可以工作,但您需要将 LdapFilter 放在双引号中
"
- PowerShell 不会在单引号内展开变量。