powershell - How to use Set-WmiInstance to save an array of objects to a property? -


in sccm trying modify manager on application request (sms_userapplicationrequest) using powershell. has array of sms_userapplicationrequesthistoryitem named requesthistory modify if current state equals 4 (accepted). cannot set-wmiinstance save wmi object property array of objects.

what doing wrong?

$class = "sms_userapplicationrequest" $server = "server.com" $sitecode = "sit" $namespace = "root\sms\site_" + $sitecode $requestguid = "0d3cc23a-eee7-404b-b4a6-7bdce112ecfa" $manager = "domain\user"  $object = get-wmiobject -namespace $namespace -class $class -computername $server -filter "requestguid='$requestguid'"  $request = [wmi]”$($object.__path)”;  $history = $request.requesthistory  if ($history -ne $null) {     foreach ($historyitem in $history)     {         if ($historyitem.state -eq 4) #4 = accepted         {             write-host "changing" $historyitem.getpropertyvalue("modifiedby") "to $manager"              $historyitem.setpropertyvalue("modifiedby", $manager)         }     } }  $history $request  set-wmiinstance -inputobject $request -arguments @{requesthistory=$history} 

requesthistory identifies array of system.management.managementbaseobject objects:

 requesthistory   : {system.management.managementbaseobject, system.management.managementbaseobject, system.management.managementbaseobject, system.management.managementbaseobject...} 

modifying object works fine, when try save set-wmiinstance error message:

 set-wmiinstance : invalid method  @ line:30 char:5 +     set-wmiinstance -inputobject $request -arguments @{requesthistory ... +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + categoryinfo          : invalidoperation: (:) [set-wmiinstance], managementexception     + fullyqualifiederrorid : setwmimanagementexception,microsoft.powershell.commands.setwmiinstance 
share|improve question

your answer

 
discard

posting answer, agree privacy policy , terms of service.

browse other questions tagged or ask own question.

Comments