Search code examples
powershellpowershell-remoting

How to Write-Verbose from Invoke-Command?


In powershell

Write-Verbose and the -Verbose flag are used to provide verbose information when commands are run in verbose mode. I am running some scripts remotely and would like to capture the verbose output output. However, Invoke-Command seems to not capture the verbose channel.

PS:> Invoke-Command -ComputerName MY-COMPUTERNAME -Verbose { Write-Verbose "blah" }
PS:>

How do I capture verbose output when running remote scripts?


Solution

  • Try it this way:

    Invoke-Command -ComputerName MY-COMPUTERNAME  {$VerbosePreference='Continue'; Write-Verbose "blah" }