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