Check if Verbose is set in PowerShell function or cmdlet


If you want to resend the Verbose preference inside a PowerShell function – which in turn, let’s say, will call 3 other cmdlets that would need to write verbose information, you can check the VerbosePreference variable:

$outputVerbose = [bool]($VerbosePreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue)
    if ($outputVerbose) {
        Write-Host “Some extra-verbose message here”
        # Or call some other functions with Verbose parameter

Note 1: Credits go to StackOverflow, IT blogs and alike, sites that helped me with the code when searching for solutions.
Note 2: Be aware that when copy-pasting, the quotes and possibly other characters get messed up by WordPress, you’ll have to replace them.


%d bloggers like this: