Author Posts

January 1, 2012 at 12:00 am

by swalkerswalker at 2012-11-13 11:45:20

I am trying to find all computers in AD that are disabled and have a date in the description of 30 days ago or more. I cannot seem to get it to properly compare the date in the description. Could someone please enlighten me:) This is what I have but does not pull the correct info.

$d = (get-date).adddays(-30);Get-ADComputer -filter {(Enabled -eq $false) -and (description -lt $d)} -properties description | ft name, description

Thanks for any assistance given...

by mikefrobbins at 2012-11-13 19:05:41

You can't use the description property until after the first pipeline (because it doesn't contain a value before it).

$d = (get-date).adddays(-30);Get-ADComputer -filter {Enabled -eq $false} -properties description | where {$_.description -lt $d} | ft name, description

If this doesn't work, post an example of the format of the date in the description field. Results will vary depending on the format of the date in the description field. $d contains a datetime object and description is a string so there's some implicit conversion going on that could possibly skew the results also.

by shizzledizzle at 2012-11-14 07:26:49

Thanks for the assistance... the word string truned on a light bulb in my head:) I got it to work by changing the disable scripts description field format and the changing the search variable.

Disable Script: $disabledate = (Get-Date).tostring("yyyyMMdd")
Search : $d = (Get-Date).adddays(-90).tostring("yyyyMMdd")

$d = (Get-Date).adddays(-90).tostring("yyyyMMdd");Get-ADComputer -filter {(Enabled -eq $false) -and (description -lt $d)} -properties description | ft name, description
The "where" did not seem to work it would pull out all disabled computers to include the ones with the desctiption.

Again thanks a ton have a great week!

by mikefrobbins at 2012-11-14 11:47:10

Glad you were able to figure it out.
I did some more testing and yeah the command I previously posted didn't accomplish what I was attempting to do. I guess my prior tests were too narrow to return the incorrect results. I learned something too, you can use the description field before the pipeline and since it's possible, that's definitely what you want to do (filter left).