I am just beginning to learn powershell and I am trying to determine some of my older Active Directory account that have not logon in over 30 days. I have the quest snapin for Active Directory Manament added and registered. The command I am using and is not working is the follwoing.
Get-qaduser |get-member -lastLogon -gt 30
What I am having trouble with is I know that -lastlogon is a property of get-qaduser , but how do I know what the proper systax is suppose to be for -lastLogon? Can someone help me?
Try a single user so you get only 1 instance of the object and look at the properties. The result of Get-qaduser username |get-member should show the methods and properties. The properties are simply values returned. To focus on the methods and thier inputs try
Get-qaduser username |get-member -membertype method
The way you are trying, you have an array of objects (many users ) if you are not specifying one. So you have to operate on each (% = foreach)
PS > $today = [DateTime]::Today;
PS> Get-QADUser | %{$diff= $today-$_.LastLogon;write-host "`n`n$($_.Lastlogon) $($_.name) $($diff.TotalDays) " }