powershell - Creating a PS query for get-adcomputer -


i trying csv of computers in security group "security group a" , filter based on lastlogontimestamp computers haven't logged on 60 days not in result. have tried few different ways not having luck. wondering if can assist. have tried

`$lastlogon = (get-date).adddays(-60).tofiletime()  get-adgroupmember "security group a" | select name 

i not sure how can pipe out here. have tried using variable of $comp error not being ad object rather system object.

the other option

$lastlogon = (get-date).adddays(-60).tofiletime() get-adgroup "security group a" -properties members | %{$_.members} | %{get-adcomputer $_ |select name | out-file c:\temp\output.csv  

with last 1 have tried add

-filter {lastlogontimestamp -gt $lastlogon} 

after $_ , before seems return empty csv (i know there results).

i doing wrong...any ideas? thanks

try this

[datetime]$lastlogon = (get-date).adddays(-60).tofiletime()  $computers = get-adgroupmember "security group a" | select-object name,@{name="stamp"; expression={[datetime]::fromfiletime($_.lastlogontimestamp)}}  $computers | {$_.lastlogontimestamp -gt $lastlogon} | select name | out-file c:\temp\output.csv -force 

tested distribution group, should work in security group


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -