2016-07-18 7 views
1

Ich habe dieses Skript versucht, inaktive Benutzer von AD zu ziehen, aber wenn jemand keinen Titel hat, werden sie nicht abgeholt. Ich habe die Logik eines leeren Titels für einen einzelnen Benutzer getestet, der als wahr zurückgegeben wurde, aber wenn er durch die foreach läuft, funktioniert er nicht (die Ausgabe zeigt nur Personen mit einem Titel sind gültig). Ich dachte, dass der letzte Logontimestamp-Vergleich nicht funktionierte, also fügte ich lastlogondate hinzu, aber scheint der Titel immer noch das Problem zu sein, und ich habe keine Idee warum?PowerShell -Filter bei -nichtem Vergleich

#Inactivity Process 

Import-Module ActiveDirectory 

# Gets time stamps for all User in the domain that have NOT logged in since after specified date. Exludes Prism and PlanLink providers. 
$DaysInactive = 365 
$time = (Get-Date).Adddays(-($DaysInactive)) 
$Out_file = "C:\scripts\adcleanup\Inactivity-365days-or-longer_$((Get-Date).ToString('MM-dd-yyyy')).csv" 
$Out_file2 = "C:\scripts\adcleanup\FailInactivity-365days-or-longer_$((Get-Date).ToString('MM-dd-yyyy')).csv" 

# Get all AD User with lastLogonTimestamp less than our time and set to enabled. Check All Users for this... 
$Users = Get-ADUser -Filter {samaccountname -like "s0*" -and (enabled -eq $true) -and (Title -notlike "*PRISM*") -and (Title -notlike "*PlanLink*") } -Properties samaccountname,name,enabled,Title,LastLogontimestamp, lastlogondate | 
select SamAccountname,Name,Title,@{Name="LastLogonTimeStamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}},lastlogondate, enabled 


Foreach ($User in $Users) { 

    If (($user.LastLogontimestamp -le $time) -or ($user.LastLogondate -le $time)) { 

     $User| export-csv $Out_file -notypeinformation -append 

     } 

    Else { 

     $User | export-csv $Out_file2 -notypeinformation -append 

     } 
     } 

Antwort

0

Ich fand es heraus.

If (($user.LastLogontimestamp -le $time) -or ($user.LastLogondate -le $time) -or ($user.title -eq "") -and ($user.title -notlike "*PRISM*") -and ($User.title -notlike "*Planlink*") -and (!([string]::IsNullOrEmpty($user.lastlogondate)))) { 
Verwandte Themen