Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Error Handling when piping output in workflow using inline script

$
0
0
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

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>