mardi 17 octobre 2023

Get random AD user from certain group where user needs to be active and lastlogintimestamp greater than 14 days

I need to get the name and SamAccountname of one random user that is in a specific group.

So far ive got the randomizer working as intented, but ass soon as i try to filter get-AdUser im sol.

this is what i have as of now:

$date = (Get-Date).AddDays(-14)

$randomUser = (Get-ADGroupMember GROUP) |Sort-Object{Get-random} | select -first 1 | Get-Aduser -Properties name,SamAccountName #-filter {name -and SamaccountName -and LastLogonTimestamp -gt $date -and enabled -eq $true}

As soon as i uncomment the bold part it stops working.

Any ideas and help would be apriciated.

I think its because i cannot filter on that output, but i dont know how to otherwise do it. The reason im using lastlogontimestamp is because lastLogon is not replicated.




Aucun commentaire:

Enregistrer un commentaire