1

Currently trying to use PowerShell workflow to process some remote server stuff that I am doing in parallel.

I am having no luck trying to get the Invoke-Command to log onto the server to actually work. It is not throwing an error but there also is no output to the console like there usually is with a Write-Host statement. Not seeing anything that is helping me looking through older posts.

workflow test {
    Param([System.Management.Automation.PSCredential]$cred)

    InlineScript {
        Write-Host $using:cred
        Invoke-Command -Computer "server" -Credential $using:cred  -ScriptBlock { Write-Host "hello world" } }
    }
}

#Calling the function
test $cred
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
lmurdock12
  • 943
  • 1
  • 7
  • 14
  • Don't use workflows just to run stuff in parallel (you can do that with jobs or runspaces). Not only are workflows significantly slower than regular PowerShell, but there are also [subtle differences](https://devblogs.microsoft.com/scripting/powershell-workflows-restrictions/) to normal PowerShell, b/c workflows are running in a different engine. Workflows have their use when you know what you're doing, but don't use them just because. – Ansgar Wiechers Jul 23 '19 at 09:21
  • @AnsgarWiechers Thank you! This turns out to be a much more elegant solution instead and I like the fact that this keeps it all within the powershell environment . – lmurdock12 Jul 23 '19 at 16:33

1 Answers1

0

write-output instead of write-host works. Note that this runs in parallel too:

invoke-command computer1,computer2,computer3 { 'whatever' } 

By the way, you have an extra curly bracket at the end.

Another way to do it:

workflow test {
  InlineScript {
    Write-Host 'hello world'
  }
}

test -pscomputername server -pscredential $cred
js2010
  • 23,033
  • 6
  • 64
  • 66