I have the following function that I am trying to invoke remotely with verbose output, but I don't know how to pass the VerbosePreference correctly?
function TestVerbose()
{
[CmdletBinding()]
Param()
Write-Output "output test"
Write-Verbose "verbose test"
}
Invoke-Command -ComputerName computerB -ScriptBlock ${function:TestVerbose}
The question How to Write-Verbose from Invoke-Command? nicely describes how to write something verbose if I have a non-function scriptblock:
Invoke-Command -ComputerName computerB {$VerbosePreference='Continue'; Write-Verbose "verbose test"}
However, I would like to pass a function and also indicate verbose preference. How to do that?
I have tried combining the function with some inline scriptblock, but it makes the function not run at all:
Invoke-Command -ComputerName computerB -ScriptBlock {$VerbosePreference='Continue'; ${function:TestVerbose}}