Return values from a workflow

by dft277 at 2012-11-23 11:15:04

I’m still trying to get my head around this workflow stuff. So far it seems quite powerful. However I’m having trouble getting return values or status updates from within the workflow stream. Just for education purposes I’m playing with a script to get a list of DC’s and ping each one and return the IP address and response time.


$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$allDCs = $dom.FindAllDomainControllers() | select -ExpandProperty Name

workflow Test-DCConnection {
param([string]$Computers)
$results = foreach -parallel ($computer in $computers) {
$IP = inlinescript { (Test-Connection -ComputerName $using:computer -Count 1)}
$IP.ipv4address.ipaddresstostring + " " + $IP.responseTime
} # end foreach loop
} # end WorkFlow

Test-DCConnection -Computers $allDCs
$results


If I remove the $resulst = it will spew the results to the screen but I’d like to have them in a variable for further processing. Where have I gone wrong ?
by DonJ at 2012-11-23 12:00:53
Well…

This is a scope issue, and while it’s harder in a workflow what you’re doing wouldn’t work in a normal function, either. $results is created within the workflow, and doesn’t exist outside of it. And you’re not spewing results to the screen, you’re spewing them to the pipeline. Which is what’s useful. The right thing to do is to remove $results= inside the workflow. Then, set $results=Test-DCConnection.

This is really the same as you’d do for a function.
by coderaven at 2012-11-23 12:08:36
In your Test-Connection, use the -Quiet switch so that you will not see the ping testing stuff, that may be all you need.

Is that your concern.
by dft277 at 2012-11-23 12:40:16
@DonJ, that’s what I was trying to accomplish. Thanks.