getting using variable to evaluate within inline script within workflow

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Stuart Douglas Stuart Douglas 4 months, 2 weeks ago.

  • Author
    Posts
  • #61380
    Profile photo of Stuart Douglas
    Stuart Douglas
    Participant

    I'm creating a script to run monthly that will control monthly security patching of my SCOM environment so that nothing is talking to the SQL servers when they reboot. The issue I'm having is getting the -ComputerName variable to evaluate (see the code snippet below). I can run this section of the script successfully as long as I exclude it from the workflow and handle the for each block sequentially, but I'd like this to run in parallel to minimize the total duration of the process. What am I doing wrong with that using variable?

    Workflow MonthlyPatching
    {
        # injest parameter valuations
        Param
        (
            [array]$omsrvrs
        )
        
        # install patches
        ForEach -Parallel ($omsrvr in $omsrvrs)
        {
            InlineScript
            {
                # invoke patch installation
                ([wmiclass]'ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager').InstallUpdates([System.Management.ManagementObject[]] (Get-WmiObject -Query "SELECT * FROM CCM_SoftwareUpdate" -Namespace "ROOT\ccm\ClientSDK" -ComputerName $Using:omsrvr))
                
                # evaluate installation status of patches
                $Installing = @(get-wmiobject -query "SELECT * FROM CCM_SoftwareUpdate WHERE EvaluationState = 6 or EvaluationState = 7" -namespace "ROOT\ccm\ClientSDK" -computer $Using:omsrvr)
                While ($Installing -ne $null)
                {
                    Start-Sleep -Seconds 600
                    $Installing = @(get-wmiobject -query "SELECT * FROM CCM_SoftwareUpdate WHERE EvaluationState = 6 or EvaluationState = 7" -namespace "ROOT\ccm\ClientSDK" -computer $Using:omsrvr)
                }
            }
        }
    }
    
  • #61387
    Profile photo of Dan Potter
    Dan Potter
    Participant

    the parameter is computername not computer?

    • #61390
      Profile photo of Stuart Douglas
      Stuart Douglas
      Participant

      Yes, ComputerName. It works fine outside of the workflow/inlinescript, it's just run from there that the variable won't evaluate.

You must be logged in to reply to this topic.