[dateTime] format directly into that WMI time format. (You can find it here).
So lets cast it !
Ok. That was easy.
Ho but wait. I haven’t set a start date THAT long ago in the past.
Software update deployment example
I actually made it available on the 06 of december 2013. Not the 12 of july 2013 as you can see on the screenshot below.
An importing thing to note here, is that the time format returned by the SQL query is in US time format.
Which means that if you work in Europe, well, you will have to convert that as well !
Actually, the solution here is pretty simple (once you know it of course !) but since casting doesn’t work, what other possibilites do we have ? Get-date ? Ok. Le’s give it a try !
Parsing sql time
So thats more like it ! Now we can use this value returned value with my Convert-ToWMITime function.
So, this was for the easy part. Because you can easily find informatino on the interent on what time format the WMI SMS_SoftwareUpdateAssignment class needs for the startime property.
But now we have all our properties, but the Put() methods still throws us generic error messages.
We got used in powershell to have a more specefic message. At least it would mention the parameter that is incorrect. But here, we have nada, niete, rien, nothing !
Even in the $error default variable there is not more informatino available. So how do we find detailed information on this WMI error ?
On the WMI error itself, i still dont know actually (Please let us know if YOU know how to have more information about an WMI error used in PowerShell).
Since i am scripting things related to SCCM, there is actually one log file that is going to help us A LOT : The SMSprov.log
On Windows-noob.com it says that Smsprov.log – Records WMI provider access to the site database
Which is exactly what we are looking for !
[important]The SMSProv.log file is generaly located here : “C:\Program Files (x86)\Microsoft Configuration Manager\Logs\smsprov.log“[/important]
(Detailed information about configMgr log files can be found here : http://www.windows-noob.com/forums/index.php?/topic/1105-sccm-logs/)
So lets look into this error file :
And tadaa ! We have finally INFO !!
We now can see that the problem seems to come from the ‘ UseGMTTimes’ property. It is NULL, but ican’t be NULL.
After a quick verification, i could see the following:
$UseGMTime = 0
Logic, since the SQL query only returns strings. (Is it logic ??).
Anyways, i resolved this by casting the SQL return directly to a bolean value.
(Casting any number, negative or positive value except for 0, to a [bool] will convert the value to $true.
Casting 0 to [bool] will return $false)
So i fixed the first issue like this :
$UseGMTime = [bool]0
$NewSoftwareUpdateAssignment.UseGMTTime = $UseGMTime
By relaunching the console i had another error.
WMI .Put() error 2
(Actually it was the same as you can see on the image above).
I checked the SMSProv again, and found this this time:
SmsProv.log error 2
After checking my function, i noticed i had a typo in my variable “$LogComplianceToWinEvent”.
I correct it. And tadaaa ! It worked !!
So, if there is one thing you need to remeber :
- SMSProv.log (If you are scripting with SCCM)
- Types ! (Especially if you are working with results that are extracted from SQL queries and not from WMI).
- Culture. As in the example of the starttime, it might work during your tests, but the dates could be wrong. Rember that if you work in europe, the SQL times returned are probably not fitting the european datetime format.
But that is 3 things ! ? Yes yes, i know. Doesn’t matter. Let’s say it is one thing that is composed of three elements 🙂