2017-10-26 2 views
0

有効になっているユーザー、ログオンしていないユーザー、または60日間ログインしていないユーザーを一覧表示する必要があります。有効になっているユーザー、60日以内にログオンしていないユーザー、または60日間にログオンしていないユーザーを一覧表示するPowerShellスクリプト

PowerShellを以前に使用したことがないと思いますが、明らかにさまざまなエラーメッセージが出てくるので、間違いがあります。

Get-ADUser -Filter { Enabled -eq $true } -Properties LastLogonDate | where { ($_.LastLogonDate.AddDays(60) -lt $(Get-Date)) -or (-not $_.LastLogonDate-like "*")) } | Select-Object SamAccountName | Format-Table 
+0

[OK]を。エラーは何ですか? –

+0

'LastLogonDate.AddDays(60)' AddDaysを切り捨て、 '(Get-Date).AddDays(-60)'に追加します。さらに '-not'を削除し、代わりに' -notlike'比較演算子を利用します。これらの変更によって、 'Where-Object'ブロックに余分な括弧は必要ありません。 – TheIncorrigible1

答えて

-1

この

Get-ADUser -Filter { Enabled -eq $true } -Properties LastLogonDate | where{ (($_.LastLogonDate.AddDays(60) -lt $(Get-Date)) -or (-not $_.LastLogonDate-like "*")) } | Select-Object SamAccountName | Format-Table 

あなたのブラケットが、より具体的に、このブラケットは、余分な

(-not $_.LastLogonDate-like "*")) // extra closing bracket 
+0

これは特別なことではありません。それは両端をカプセル化します。 – TheIncorrigible1

+0

まあまあです。私はあなたがペアを見ることができるように、 'すべてのブラケットの後に番号を記入します(。_ <1> $をLastLogonDate.AddDays(<2> 60)<2> -lt $(<3>のGet-日)<3>)<1> -or(<4> -not $ _。LastLogonDate 「*」と同様)<4>)「 – pandemic

+0

です。私はOPの代わりにあなたのコード例を見ていました。 – TheIncorrigible1

-1

私のコメントを取り、それに答えなっている、正しいしゃべれなかっ試してみてください。

Get-ADUser -Filter { Enabled -eq $True } -Properties LastLogonDate | 
    #Tests whether LastLogonDate is older than 60 days or if it's $Null 
    Where-Object { $_.LastLogonDate -lt (Get-Date).AddDays(-60) -or 
       -not $_.LastLogonDate } | 
    Select-Object -Property SamAccountName | 
    Format-Table 
関連する問題