Author Posts

August 21, 2015 at 1:29 pm

Can not figure out why I'm getting error below on line 16

+ GetComputerName "localhost"
+ ~
Missing '=' operator after key in hash literal.

workflow GetComputerName
{
param ([String[]] $computerNames)
$scriptblock = @{
$result= [pscustomobject]@{"MachineName" = $env:ComputerName}
Get-Date
}

foreach -parallel ($computername in $computerNames)
{
$workflow:out += inlinescript {Invoke-Command -ComputerName $computername -ScriptBlock ([scriptblock]::Create($using:scriptBlock))}
}

}

GetComputerName "localhost"

August 21, 2015 at 2:09 pm

GS,

It's complaining because
$scriptblock = @{
should be
$scriptblock = {

But try something like this this instead.

workflow GetComputerName
    {
    Param ( [String[]] $ComputerNames )

    ForEach -Parallel ($ComputerName in $ComputerNames)
        {
        InlineScript
            {
            [pscustomobject]@{ "MachineName" = $env:ComputerName }

            } -PSComputerName $ComputerName
        }
    }

GetComputerName "localhost"

You should also add a -ThrottleLimit 100 (or whatever) to your ForEach -Parallel. Otherwise, if you accidentally grab 5000 server names from AD and try to launch a separate thread for each, you are going to crash your computer.

August 21, 2015 at 4:28 pm

Thanks, so InlineScript with -PsComputerName is acting like Invoke-Command equivalent in workflow?