Hi Gang,<\/p>\n
Any ideas what I might be doing wrong here?<\/p>\n
Target it to find all NON Server AD Computer objects with LastLogonTimeStamp defined in $time<\/p>\n
Get-ADComputer -Filter {(('OperatingSystem -NotLike \"*Server*\"') -and (LastLogonTimeStamp -lt $time))} -Properties * | Select -Property Name,operatingSystem,@{Name=\"LastLogon\";Expression={[DateTime]::FromFileTime($_.lastLogon).ToString()}}\n<\/code><\/pre>\nThanks, much appreciated.<\/p>","upvoteCount":4,"answerCount":5,"datePublished":"2019-06-11T02:55:51.000Z","author":{"@type":"Person","name":"nitinpandey2","url":"https://community.spiceworks.com/u/nitinpandey2"},"acceptedAnswer":{"@type":"Answer","text":"
I guess filter is wrong here<\/p>\n
Get-ADComputer -Filter {OperatingSystem -notLike “*Server*” -and LastLogonTimeStamp -lt $time} -Properties operatingSystem,lastLogontimeStamp | \nSelect Name,operatingSystem,@{Name=\"LastLogon\";Expression={[DateTime]::FromFileTime($_.lastLogontimeStamp).ToString()}}\n\nget-ADcomputer -filter * -prop OperatingSystem,lastLogontimeStamp|where{$_.OperatingSystem -notLike “*Server*” -and $_.LastLogonTimeStamp -lt $time}|\nSelect -Property Name,operatingSystem,@{Name=\"LastLogon\";Expression={[DateTime]::FromFileTime($_.lastLogontimestamp).ToString()}}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-06-11T03:08:55.000Z","url":"https://community.spiceworks.com/t/ad-computers-old-and-not-server-powershell-query/715772/2","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},"suggestedAnswer":[{"@type":"Answer","text":"Hi Gang,<\/p>\n
Any ideas what I might be doing wrong here?<\/p>\n
Target it to find all NON Server AD Computer objects with LastLogonTimeStamp defined in $time<\/p>\n
Get-ADComputer -Filter {(('OperatingSystem -NotLike \"*Server*\"') -and (LastLogonTimeStamp -lt $time))} -Properties * | Select -Property Name,operatingSystem,@{Name=\"LastLogon\";Expression={[DateTime]::FromFileTime($_.lastLogon).ToString()}}\n<\/code><\/pre>\nThanks, much appreciated.<\/p>","upvoteCount":4,"datePublished":"2019-06-11T02:55:51.000Z","url":"https://community.spiceworks.com/t/ad-computers-old-and-not-server-powershell-query/715772/1","author":{"@type":"Person","name":"nitinpandey2","url":"https://community.spiceworks.com/u/nitinpandey2"}},{"@type":"Answer","text":"
How did you define $time ? What errors are you getting? Heres what I use to find InActive Computer Objects:<\/p>\n
import-module activedirectory \n\n#change OU if needed, use Distinguished Name\n$domain = \"Put your OU Distinguished Name here\" \n\n#change to query how many days since\n$DaysInactive = 45 \n\n$time = (Get-Date).Adddays(-($DaysInactive)) \n \n# Get all AD computers with lastLogonTimestamp less than our time \nGet-ADComputer -Searchbase $domain -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp | \n \n# Output hostname and lastLogonTimestamp into CSV, change save location if needed \nselect-object Name,@{Name=\"Last Logon\"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv e:\\scripts\\Inactive_Computers45Day.csv -notypeinformation\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-06-11T03:49:36.000Z","url":"https://community.spiceworks.com/t/ad-computers-old-and-not-server-powershell-query/715772/3","author":{"@type":"Person","name":"robertmartinez3","url":"https://community.spiceworks.com/u/robertmartinez3"}},{"@type":"Answer","text":"