Basicly我想找到不活動的用戶,以便用在搜索基礎foreach循環,POWERSHELL - 使用數組在foreach的樣子,看着一個OU中的用戶 -
IM現在我試着去impliment看着幾個OU在開始的時候就是一個陣容。
原來這就是我試圖...
[email protected]("OU Path 1",
"OU Path 2",
"OU Path 3")
$OU | ForEach ($user in (Get-ADUser -SearchBase $_ -filter {(lastlogondate -notlike "*" -OR lastlogondate -le $90days) -AND (passwordlastset -le $90days) -AND (enabled -eq $True)} -Properties lastlogondate, passwordlastset | Select-Object name, lastlogondate, passwordlastset, samaccountname))
{
....
,並得到錯誤....
At line:18 char:22 + $OU | ForEach ($user in (Get-ADUser -SearchBase $_ -filter {(lastlogondate -notl ... + ~~ Unexpected token 'in' in expression or statement. At line:18 char:21 + $OU | ForEach ($user in (Get-ADUser -SearchBase $_ -filter {(lastlogondate -notl ... + ~ Missing closing ')' in expression. At line:18 char:293 + ... samaccountname)) + ~ Unexpected token ')' in expression or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
這工作得很好
$SearchBase1 = "OU1"
$SearchBase2 = "OU2"
$SearchBase3 = "OU3"
ForEach ($user in(Get-ADUser -SearchBase $SearchBase1 -filter {(lastlogondate -notlike "*" -OR lastlogondate -le $90days) -AND (passwordlastset -le $90days) -AND (enabled -eq $True)} -Properties lastlogondate, passwordlastset | Select-Object name, lastlogondate, passwordlastset, samaccountname))
{