How do I use here-string for ScriptBlock variable?

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”

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.

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