Do the newer CIM cmdlets follow a different protocol for remote systems?

Viewed 88

I've been trying to install some remote updates that are in error state (well any updates in general), but continue to get and error of:

No instance found with given property values. 

. . that's it. That's the only error that is displayed with no further info given. Looking at the the documents for Invoke-CimMethod, it show's that it expects an argument of: [[-Arguments] <IDictionary>], which is fine, but i'm just not understanding what I may be doing wrong.

Currently I am grabbing the available updates on the remote system. Outputting to Out-GridView for a selection, and using Invoke-CimMethod to try and invoke the installation:

Invoke-CimMethod -Namespace $nameSpace `
                 -ClassName "CCM_SoftwareUpdatesManager" `
                 -CimSession $CIMSession `
                 -Arguments @{ 
                    CCMUpdates = [ciminstance[]]$_ 
                 } -MethodName "InstallUpdates" -ErrorAction Stop

So far, from other posts like this one, the argument value has to be of CIMInstance; which they are when running .GetType().FullName on the current instance from the pipeline: Microsoft.Management.Infrastructure.CimInstance. . .but, according to that same post with the same error, the issue was that the instances had to not have been saved to a variable? Only way that would make sense is that it needs to not be a de-serialized instance? Either way, I gave their suggestion a try but, still got the same error.

Question: Is there something that I am doing wrong with passing the arguments to the command for it to continue to give me that error?

So here is the rest of the code in hopes that someone smarter than me can help me understand what is the cause here:

Function Install-SCUpdates {
    Param (
        [Parameter(Mandatory=$true,
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true)]
        [string[]]$ComputerName,

        [Parameter(Mandatory=$false)]
        [switch]$Force
    )
    Begin
    {
        $nameSpace = "root\ccm\clientSDK"
        $className = "CCM_SoftwareUpdate"

        $EvaluationState = @{
            0  = 'None'
            1  = 'Available'
            2  = 'Submitted'
            3  = 'Detecting'
            4  = 'PreDownload'
            5  = 'Downloading'
            6  = 'WaitInstall'
            7  = 'Installing'
            8  = 'PendingSoftReboot'
            9  = 'PendingHardReboot'
            10 = 'WaitReboot'
            11 = 'Verifying'
            12 = 'InstallComplete'
            13 = 'Error'
            14 = 'WaitServiceWindow'
            15 = 'WaitUserLogon'
            16 = 'WaitUserLogoff'
            17 = 'WaitJobUserLogon'
            18 = 'WaitUserReconnect'
            19 = 'PendingUserLogoff'
            20 = 'PendingUpdate'
            21 = 'WaitingRetry'
            22 = 'WaitPresModeOff'
            23 = 'WaitForOrchestration'
        }
    }
    Process
    {
        foreach ($Computer in $ComputerName)
        {
            Try {
                $CIMSession   = New-CimSession -ComputerName $Computer -ErrorAction Stop
                $updatesFound = Get-CimInstance -Namespace $nameSpace -ClassName $className -CimSession $CIMSession
                    if ($updatesFound) {
                        if ($Force) {
                            $null = Invoke-CimMethod -MethodName "InstallUpdates" -Namespace $nameSpace -ClassName "CCM_SoftwareUpdatesManager" -Arguments @{CCMUpdates = [ciminstance[]]$updatesFound} -CimSession $CIMSession
                            $updatesFound | Select-Object -Property ArticleID, 
                                @{
                                    Name='Status';
                                    Expression = {
                                        $Code = [int]$_.EvaluationState.ToString().Trim()
                                        $EvaluationState.$code
                                    }
                                }, Name
                        }
                        else {
                            $selectedSoftware = $updatesFound | Select-Object -Property ArticleID, 
                                @{
                                    Name='Status';
                                    Expression = {
                                        $Code = [int]$_.EvaluationState.ToString().Trim()
                                        $EvaluationState.$code
                                    }
                                }, Name,Description | Out-GridView -Title $Computer -PassThru
                                if ($selectedSoftware) {
                                    $selectedSoftware = $updatesFound.Where{
                                        $_.Name -in $selectedSoftware.Name
                                    }
                                    $selectedSoftware  | ForEach-Object -Process `
                                    {
                                        #$_.GetType().FullName
                                        #$cimInstance = [ciminstance[]](Get-CimInstance -Query "SELECT * FROM $className WHERE updateID='$($_.UpdateID)'" -Namespace $nameSpace -CimSession $CIMSession)
                                        #$cimInstance | gm 
                                        #Invoke-CimMethod -MethodName "InstallUpdates" -Namespace $nameSpace -ClassName "CCM_SoftwareUpdatesManager" -Arguments @{CCMUpdates = $cimInstance } -CimSession $CIMSession
                                        #Invoke-CimMethod -InputObject $_ -MethodName InstallUpdates -CimSession $CIMSession
                                        $updateID = $_.UpdateID
                                        Invoke-CimMethod -Namespace $nameSpace `
                                                         -ClassName "CCM_SoftwareUpdatesManager" `
                                                         -CimSession $CIMSession `
                                                         -Arguments @{ 
                                                            CCMUpdates = [ciminstance[]]$_ 
                                                        } -MethodName "InstallUpdates" -ErrorAction Stop
                                        
                                    }
                                    
                                    $selectedSoftware | Select-Object -Property "ArticleID", 
                                        @{
                                            Name='Status';
                                            Expression = {
                                                $Code = [int]$_.EvaluationState.ToString().Trim()
                                                $EvaluationState.$code
                                            }
                                        }, "Name"
                                }
                                else {
                                    Write-Host -Object "No software selected to install.`n"
                                    Continue
                                }
                        }
                    }
                    else {
                        Write-Host -Object "No updates Found!:)"
                    }
            }
            Catch {
                Write-Host -Object $_.Exception.Message -ForegroundColor Red -BackgroundColor Black
            }
            Finally {
                if (Get-CimSession) {
                    Get-CimSession | Remove-CimSession
                }
            }
        }
    }
    End { }
}

There really shouldn't be no expected output other than that of the command actually running successfully.

0 Answers
Related