Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Why is -Verbose not working with Invoke-Command?

$
0
0

I have the following script:

    try {Invoke-Command-Computer $Server -ScriptBlock{Get-ChildItem-Path $Directory |Where{$_.Name-Match"$DB"}|Remove-Item-confirm:$false -Recurse $VerbosePreference='Continue';-Verbose}#-VerboseWrite-Host"`r`nsuccessfull! "-foregroundcolor yellow -backgroundcolor black}
    catch {
        write-host "`r`nFAILED!"-foregroundcolor red -backgroundcolor blackWrite-Host"$($error[0])`r`n"-foregroundcolor magenta -backgroundcolor black}

-verbose is not generating any verbose like this:

VERBOSE: Performing the operation "Remove File" on target ...

if i try the following command:

Get-ChildItem-Path'E:\' | Where{$_.Name -Match "text"} | Remove-Item -confirm:$false -Recurse
 -Verbose

I actually get back:

VERBOSE: Performing the operation "Remove File" on target "E:\text.xml".

VERBOSE: Performing the operation "Remove File" on target "E:\text.txt".

according to this thread:

How to Write-Verbose from Invoke-Command?

I am supposed to use $VerbosePreference='Continue';

but i already tried that as you can see and still i cant get verbose to output anything!

also, even though no folders get deleted, apparently, my try catch STILL outputs that it was successfull...

how come?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>