torsdag, november 19, 2009
How to get $VerbosePreference applied on remote commands
If you use Write-Verbose in a script executed on a remote computer, you may not get the result you expect.
The above will only output "hello" and not "there" in the host window.
I thought I was clever by just passing along the $VerbosePreference value:
But, still no luck! Only the statement using Write-Host is included in the output when the command is invoked on the remote computer.
What's going on here is that the argument sent to the remotely executed script block is converted to an integer, which is the base integral type of the underlying enum type of $VerbosePreference.
So I figured that typing the argument in the param() clause will bind the parameter to the correct data type, and voila, it now works as expected.
Now you can toggle the verbose output of your remote script using the switch of your local script:
Example TestRemoteCommand.ps1:
The above will only output "hello" and not "there" in the host window.
I thought I was clever by just passing along the $VerbosePreference value:
But, still no luck! Only the statement using Write-Host is included in the output when the command is invoked on the remote computer.
What's going on here is that the argument sent to the remotely executed script block is converted to an integer, which is the base integral type of the underlying enum type of $VerbosePreference.
So I figured that typing the argument in the param() clause will bind the parameter to the correct data type, and voila, it now works as expected.
Now you can toggle the verbose output of your remote script using the switch of your local script:
Etiketter: powershell, winrm
Prenumerera på Inlägg [Atom]



