Remove the casts of Get-CimInstance output to [CimInstance[]] to allow the module to be used on non-Windows platforms that don't have [CimInstance]. Tested on macOS and Windows, but Linux should work too.
Fix using Invoke-CCMSoftwareUpdate using a PSSession. PSSessions have to be used from non-Windows platforms, so this contributed to the above.
CimInstance and cim cmdlets are Windows-only, so anything using them elsewhere errors. Fortunately, most of the usage here isn't strictly required- most of the usage is casting the output from Get-CimInstance to [CimInstance[]], which is not usually required.
On Windows, gcim or icm {gcim} return an Object[] containing CimInstances, so the casting is ensuring the result is an array, and changing the containing array's type.
On macOS (and presumably Linux) icm {gcim} returns an Object[] containing PSObjects due to the lack of CimInstance
Casts were change to [array] rather than [object[]] to be clearer that they're there to ensure the result is an array, rather than objects.
The only situation (I think) where a [CimInstance[]] specifically is required is CCM_SoftwareUpdatesManager's InstallUpdates() method, which is solved by doing the cast to [CimInstance[]] on the target machine via Invoke-Command, which will always have the type available if Invoke-CimMethod is going to work.
Get-CimInstance
output to[CimInstance[]]
to allow the module to be used on non-Windows platforms that don't have[CimInstance]
. Tested on macOS and Windows, but Linux should work too.Invoke-CCMSoftwareUpdate
using a PSSession. PSSessions have to be used from non-Windows platforms, so this contributed to the above.CimInstance
and cim cmdlets are Windows-only, so anything using them elsewhere errors. Fortunately, most of the usage here isn't strictly required- most of the usage is casting the output fromGet-CimInstance
to[CimInstance[]]
, which is not usually required.gcim
oricm {gcim}
return anObject[]
containingCimInstance
s, so the casting is ensuring the result is an array, and changing the containing array's type.icm {gcim}
returns anObject[]
containingPSObject
s due to the lack ofCimInstance
[array]
rather than[object[]]
to be clearer that they're there to ensure the result is an array, rather than objects.The only situation (I think) where a
[CimInstance[]]
specifically is required isCCM_SoftwareUpdatesManager
'sInstallUpdates()
method, which is solved by doing the cast to[CimInstance[]]
on the target machine viaInvoke-Command
, which will always have the type available ifInvoke-CimMethod
is going to work.