jeudi 28 juillet 2016

Different time formats in same variable

I am writing a script that is filtering for computer accounts in AD. I want to disable/delete all accounts that are at least inactive for more than 90 days . If they are inactive for at least 90 days they should be disabled and if inactive for more than 180 days they should be deleted

So, I get the dates for disabling and deleting

$disbale= (Get-Date).AddDays(-90)
$delete = (Get-Date).AddDays(-180)

Now I loop through a given OU and get all accounts that are at least 90 days inactive, therefore I also get those that are inactive for more than 180 days, too.

$acc = Get-ADcomputer -Filter {LastLogonTimeSTamp -lt $disable)} -Properties LastLogonTimeStamp,Description -SearchBase "OU=Computer,DC=dom,DC=de" -Server dom

Then I would put them into a foreach to disbale or delete them

foreach ($pc in $acc) {if($pc.LastLogonTimeSTamp -lt $delete){write-host 'delete'} else {write-host 'disable'}}

But here I ran into the error that $pc.LastLogonTimeSTamp is of type [int64] and is a number of 18 digits and $delete is in format time. But why did the same comparison above LastLogonTimeSTamp -lt $disable work and now it doenst? How can I work arround this easy?

Aucun commentaire:

Enregistrer un commentaire