Hello,
I have powershell code where I am using Workflow and InlineScript. I am piping output to an Object Property. For some reason Catch doesnt work when it encounters an invalid parameter. Please advice
workflow test-service
{
param([string[]]$Server,[string]$svc)
foreach -parallel ($srv in $server)
{
InlineScript
{
$props=[ordered]@{
Computer=$USING:srv;
Service=$USING:svc;
State=$null }
Try
{
$props.State=Get-WmiObject -Class Win32_Service -ComputerName $USING:srv | Where-Object {$_.Name -eq $USING:svc} | Select-Object -ExpandProperty State
}
Catch
{
$props.State = "$_."
}
New-Object -TypeName PSCustomObject -Property $props
}
}
}
$a = "random123456"
test-service -svc $a -Server Client1,Client2Thanks in advance.
Rajiv
I have powershell code where I am using Workflow and InlineScript. I am piping output to an Object Property. For some reason Catch doesnt work when it encounters an invalid parameter. Please advice
workflow test-service
{
param([string[]]$Server,[string]$svc)
foreach -parallel ($srv in $server)
{
InlineScript
{
$props=[ordered]@{
Computer=$USING:srv;
Service=$USING:svc;
State=$null }
Try
{
$props.State=Get-WmiObject -Class Win32_Service -ComputerName $USING:srv | Where-Object {$_.Name -eq $USING:svc} | Select-Object -ExpandProperty State
}
Catch
{
$props.State = "$_."
}
New-Object -TypeName PSCustomObject -Property $props
}
}
}
$a = "random123456"
test-service -svc $a -Server Client1,Client2Thanks in advance.
Rajiv