PowerShell workflow Invoke-Command not working (Write-Host)

844 Views Asked by At

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
1

There are 1 best solutions below

0
js2010 On

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