by grantc at 2013-01-21 16:05:55
Hi Guys,by DonJ at 2013-01-21 16:16:59
I was hoping someone could help me with a where-object issue I’m having with filtering an array…
Here’s where I’m at…
PS> $grabdate
Monday, 22 October 2012 10:57:57 AM
PS> $wmicarraycheck | where {$.installedon -ge $grabdate}
CSName description hotfixid InstalledOn
------ ----------- -------- -----------
Security Update KB2778930 18/01/13
Security Update KB2770660 18/01/13
Security Update KB2761465 18/01/13
Security Update KB2799329 18/01/13
Security Update KB2785220 18/01/13
Security Update KB2757638 18/01/13
Security Update KB2753842 18/01/13
Security Update KB2758857 18/01/13
Security Update KB2742601 18/01/13
Security Update KB2729453 18/01/13
Security Update KB978338 19/10/12
Security Update KB2731847 19/10/12
Security Update KB2744842 19/10/12
Security Update KB2712808 19/10/12
I cannot get it to filter on the InstalledOn date. It always displays the entire array. I did create a custom Label for InstalledOn as shown below;
PS> $wmicarraycheck | gm installedon
TypeName: Selected.System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
InstalledOn NoteProperty System.String InstalledOn=01/01/01
Any assistance would be much appreciated.
Thanks!
Yeah, your InstalledOn is a string, and you’re comparing it to a raw date. That’s probably the issue. Sometimes it’ll implicitly figure it out, sometimes not. You’ll want to convert InstalledOn to a real date. I don’t know how you’re defining InstalledOn, but you want it to be a DateTime, not a String. You can use the [datetime] (I think, maybe it’s just [date]) accelerator to convert a string, if that helps.by grantc at 2013-01-21 16:55:22
Thanks for that, that helps steer me on the right path… Just having trouble with the [convert] syntax…by DonJ at 2013-01-21 16:59:37
PS> $wmicarraycheck | select @{Name=‘InstalledOn’;Expression={System.DateTime]::Parse($.installedon)} }
InstalledOn
-----------
How would I use the [String]]] Option in this case? …
Syntax. Mismatched square brackets around [datetime] and you don’t need system.by grantc at 2013-01-21 18:37:01
[datetime]"1/1/2000" will call the constructor. You’re over thinking the .NET bits.
Magic - I’ve managed to get it working. Thanks for your help.