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
2
  • 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 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. Commented Jul 23, 2019 at 9: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 . Commented Jul 23, 2019 at 16:33

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.