none
Checking multiple service status for one server using Function and Workflow RRS feed

  • Question

  • Hello,

    I have a function that will check the list of service status for one machine. I am calling this function using a Workflow. For some reason, I am not getting any output. Please advice. Thanks in advance.

    #####Code for Function#####
    Function Check-Services
    {
        Param(
        [string]$Server,
        [string[]]$ServiceName
        )
           foreach ($service in $ServiceName)
           {
             $props=[ordered]@{
             ServerName=$Server;
             ServiceName=$service;
             DisplayName=$null
             StartMode=$null
             State=$null
             Date = Get-Date -Format "yyyy-MM-dd";
             Time = Get-Date -Format "HH:mm:ss"; }
    
                if(Test-Connection -ComputerName $Server -BufferSize 2 -Count 3 -Quiet)
                {
                  if($s=Get-WmiObject -Filter "Name='$service'" -class Win32_Service -ComputerName $Server)
                  {
                     $props.State=$s.State
                     $props.StartMode=$s.StartMode
                     $props.DisplayName = $s.DisplayName
                  }
                  else
                  {
                     $props.DisplayName = "Not Found"
                     $props.StartMode = "Not Found"
                     $props.State = "Not Found"
                  }
                }
                else
                {
                     $props.DisplayName = "Offline"
                     $props.StartMode = "Offline"
                     $props.State = "Offline"
                }
             New-Object -TypeName PSObject -Property $props                       
            }
             
    }
    
    #####Code for Workflow#####
    Workflow run-ServiceCheck
    {
        Param(
        [string[]]$Computers,
        [string[]]$Services
        )
    
        foreach -parallel($computer in $Computers)
        {
            InlineScript
            {
               Import-Module D:\CMHealth\Build\CMDC.psm1
               Check-Services -Server $USING:computer -ServiceName $Services
            }
    
        }
    }
    $Svc = "BITS","WUAUSERV"
    run-ServiceCheck -Computers Client1, Client2, Client3 -Services $Svc 

    Rajiv
    Friday, July 11, 2014 4:07 AM

Answers

  • Hi Rajiv,

    when you call Check-Services in the inline script of the Workflow, you've messed up the ServiceName Parameter:

    It should be $using:Services

    Otherwise it'll be null and the foreach loop in your function will never run.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Rajiv IR Friday, July 11, 2014 6:56 AM
    Friday, July 11, 2014 6:34 AM

All replies

  • Hi Rajiv,

    when you call Check-Services in the inline script of the Workflow, you've messed up the ServiceName Parameter:

    It should be $using:Services

    Otherwise it'll be null and the foreach loop in your function will never run.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Rajiv IR Friday, July 11, 2014 6:56 AM
    Friday, July 11, 2014 6:34 AM
  • My bad :) Thanks Fred
    Friday, July 11, 2014 6:56 AM