i'm trying to get all software updates from configMgr in WMI, that are older than 30 days, i just cant seem to figure it out.
Timeformat in WMI is : DateRevised : 20121113180000.000000+000
I tried the following :
$Date30DaysAgo = (get-date).AddDays(-30).ToString("yyyymmddHHMMSS")
Get-WmiObject -Namespace "root\SMS\site_PS1" -Class SMS_SoftwareUpdate -ComputerName SRVSCCM01 -Filter {"DateRevised <= '$($Date30DaysAgo)%'"}
This is working, but i need to get it working, with -Filter
and not where-object
$Date30DaysAgo = (get-date).AddDays(-30)
Get-WmiObject -Namespace "root\SMS\site_PS1" -Class SMS_SoftwareUpdate -ComputerName SRVSCCM01 | Where-Object {$_.ConvertToDateTime($_.DateRevised) -lt $Date30DaysAgo }
It's probably because i cant get the time conversion and the WQL less than operator to work.. can someone point me in the right direction ?
You could try to put $Date30DaysAgo in WMI timestamp format using:
$Date30DaysAgo = ([wmi]"").ConvertFromDateTime((get-date).AddDays(-30))
or use
$Date30DaysAgo = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime(((get-date).AddDays(-30)).ToUniversalTime())
and use that value in your filter