1

Using the SCClient Powershell module, I'm trying to install an individual update from a list of updates in the Software Center.

I can create a variable like this:

$ids = Get-SCCLientPendingUpdate *server* | select-object updateid

and $ids will output something like:

UpdateID
--------
Site_siteid/SUM_446bbb5d-743f-486c-94dc-61c3dce48e75
Site_siteid/SUM_f444ac52-95a6-4a47-95bb-51c2694120fb
Site_siteid/SUM_426ce60a-8e6e-4c8d-ae46-a1329b0b6b2c

When I try to run the following:

Start-SCClientInstallUpdates *server* -updateid $ids[0]

I get an error stating:

MethodInvocationException: Exception calling "InstallUpdates" with "1" argument(s): "Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.Array'."

Not sure of a good way to deal with this, I was thinking of assigning each updateID to its own variable as a string, but there is no information that I could find to accomplish this and seems a little clunky anyways. [string]$ids[0] outputs this:

@{UpdateID=Site_siteid/SUM_446bbb5d-743f-486c-94dc-61c3dce48e75}

I'm assuming this is part of the problem, but I can't figure out how to remove the "extra" stuff from it being an array, or how to save the original variable ($ids) differently. I can reference a variable with -updateid $var if the variable is saved like this:

$var = "Site_siteid/SUM_446bbb5d-743f-486c-94dc-61c3dce48e75"

Maybe I'm going about this wrong or missing something simple I'm not sure, but I can't find this error anywhere online and the few things I tried to convert it to a string seems to still reference the thing as an array, so I don't know what I'm missing.

I've tried: [string]$ids[0] $ids[0].updateid

setting $ids[0] to its own variable (same error as before)

$idarray = $ids | foreach {"$($_.UpdateID)"} and then using $idarray for the -updateid (same error, unable to cast object...to type 'system.array')

enclosing the variable in quotes ( -updateid "$ids[0]" , "$idarray" , etc.)

mklement0
  • 382,024
  • 64
  • 607
  • 775
lucky255
  • 11
  • 2
  • 1
    It seems you're looking for `-updateid $ids[0].UpdateID` instead of just `-updateid $ids[0]` – Santiago Squarzon Dec 30 '22 at 18:23
  • In short: [`Select-Object`](https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/select-object) (`select`) by default returns _a `[pscustomobject]` instance_ that has the _requested properties_ - even when you're only asking for a _single_ property. To get only that property's _value_, use the `-ExpandProperty` parameter instead of the (possibly positionally implied) `-Property` parameter. See the linked duplicate for details and alternatives, notably the ability to simply use `(...).SomeProperty` – mklement0 Dec 30 '22 at 18:59
  • To spell the solution out in your case: use `$ids = Get-SCCLientPendingUpdate *server* | select-object -ExpandProperty updateid` or simply `$ids = (Get-SCCLientPendingUpdate *server*).updateid` – mklement0 Dec 30 '22 at 19:04

0 Answers0