# Verbose not working with Invoke-Command...

**URL:** <https://forums.powershell.org/t/verbose-not-working-with-invoke-command/12332>\
**Category:** PowerShell Help\
**Created:** [April 3, 2019, 6:39pm UTC](https://forums.powershell.org/t/verbose-not-working-with-invoke-command/12332 "2019-04-03T18:39:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cataster](https://avatars.discourse-cdn.com/v4/letter/c/ecb155/32.png) [@cataster](https://forums.powershell.org/u/cataster)\
**Post date:** [April 3, 2019, 6:39pm UTC](https://forums.powershell.org/t/verbose-not-working-with-invoke-command/12332/1 "2019-04-03T18:39:20Z")

</div>

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 } #-Verbose

        Write-Host "`r`nsuccessfull! " -foregroundcolor yellow -backgroundcolor black
    }
    catch {
        write-host "`r`nFAILED!" -foregroundcolor red -backgroundcolor black
        Write-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?](https://stackoverflow.com/questions/16197021/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?

---

<div class="post-metadata">

**Author:** ![cataster](https://avatars.discourse-cdn.com/v4/letter/c/ecb155/32.png) [@cataster](https://forums.powershell.org/u/cataster)\
**Post date:** [April 3, 2019, 7:54pm UTC](https://forums.powershell.org/t/verbose-not-working-with-invoke-command/12332/2 "2019-04-03T19:54:33Z")

</div>

have to pass parameters into the script block:

```
Invoke-Command -Computer $Server -ScriptBlock { 
    param ($dir, $name)
    Get-ChildItem -Path $dir | 
        Where {$_.Name -Match "$name"} | 
            Remove-Item -confirm:$false -Recurse -Verbose 
} -ArgumentList $Directory, $DB
```

the reason I see nothing from the -Verbose is because the Get-Childitem didn’t find anything.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 3, 2019, 7:58pm UTC](https://forums.powershell.org/t/verbose-not-working-with-invoke-command/12332/3 "2019-04-03T19:58:48Z")

</div>

[https://social.technet.microsoft.com/Forums/en-US/aabedd38-269e-42c0-bc83-e6bd6d6d1f33/why-is-verbose-not-working-with-invokecommand?forum=winserverpowershell](https://social.technet.microsoft.com/Forums/en-US/aabedd38-269e-42c0-bc83-e6bd6d6d1f33/why-is-verbose-not-working-with-invokecommand?forum=winserverpowershell)  
[https://stackoverflow.com/questions/55505913/why-isnt-verbose-working-on-invoke-command](https://stackoverflow.com/questions/55505913/why-isnt-verbose-working-on-invoke-command)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:33pm UTC](https://forums.powershell.org/t/verbose-not-working-with-invoke-command/12332/4 "2024-05-16T20:33:03Z")

</div>

Closed on May 16, 2024, 8:33pm UTC


