Reputation: 2409
I'm writing a script that (by necessity) has to call a rather noisy set of other cmdlets. I'd like to the printing from the other cmdlets to not be displayed so I only see the status messages from my own script.
I've tried > $null
and | Out-Null
, but those only swallow returned values, not text printed via Write-Host
. How can I hide/prevent text being printed "down the stack"?
Upvotes: 5
Views: 3668
Reputation: 2152
If I've read your post correctly, you'd like to silence the Write-Host cmdlet. If we consider command precedence, we know that functions will be run before cmdlets, if they have the same name. Therefore, I'd recommend you create a Write-Host function that doesn't write anything. Here's an example that highlights this possibility.
Upvotes: 2
Reputation: 42103
Try to define your dummy function Write-Host
before calling noisy cmdlets, e.g.
function Write-Host {}
If they call Write-Host
literally then this should help.
Upvotes: 3