I am currently working on PowerShell script to create ZTI deployment with SCCM for our computers. The last step of the script is to clear the old PXE Request so that the computer will be "available" for a new deployment on the next reboot. I am currently using that WMI command that is working "ok" (except for the part that it always return a StatusCode equal to 0 even for a non-existing machine) :
Invoke-WmiMethod -Namespace "root\SMS\Site_PR1" -Class SMS_Collection -Name ClearLastNBSAdvForMachines -computername $ComputerName -ArgumentList (,"$ComputerID")
I'm trying (for curiosity and stuff) to invoke the same method with Invoke-CimSession
instead. Sadly, I don't seem to be able to build the right "argument" variable to send to the method.
I know that the method is expecting a hashtable containing a key "ResourceIDs" with values of the type MI_UINT32A.
I tried multiple way to send my arguments without success. I know the hashtable is fine, but the value seems to be the problem. I always receive a CIMException error message saying the Web Service Manager can't resolve my query because there is an invalid character, and that it can't convert the string to number (loosely translated from French):
Invoke-CimMethod : Le service Gestion des services Web ne peut pas traiter la demande, car elle contient un caractère non valide. Le service Gestion des services Web ne
peut pas convertir la chaîne en nombre. Chaîne: true. Assurez-vous que la chaîne représente le type de données approprié.
So far, my code looks like this :
$arguments = @{
ResourceIDs = [uint32[]]($ComputerID)
}
Invoke-CimMethod -CimSession $CimSession -Namespace root\sms\site_PR1 -ClassName SMS_Collection -MethodName ClearLastNBSAdvForMachines -Arguments $arguments
I've done a .gettype() on my hashtable, and it confirmed that my casting was (probably) fine :
PS C:\> $arguments.ResourceIDs.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True UInt32[] System.Array
I suppose the solution is quite obvious, but I can't see what I'm doing wrong. So any help would be appreciated!