Enable Verbose Switch for cmdlets within the Function

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Flynn Bundy Flynn Bundy 1 year, 4 months ago.

  • Author
  • #26674
    Profile photo of Kevin Bhunut
    Kevin Bhunut

    How do I enable Verbose mode for the cmdlets within the function?

    I added [CmdletBinding()] but that will only print write-verbose to screen but not enabling Verbose for New-ADUser or whatever Cmdlet I called within the script.

  • #26677
    Profile photo of Flynn Bundy
    Flynn Bundy

    Not sure I completely understand your question.
    However, You should have a look at "Get-help about_functions_advanced": With Advanced functions you can take advantage of the common -verbose parameter. Simply output your verbose output this way:

    Write-Verbose "Text of debug"

    when the shell's $VerbosePreference variable isn't set to "SilentlyContinue" ("Continue" will enable the output), you'll see your verbose output.

    Alternatively you can write your own verbose output for your script and use Write-Verbose for whichever line you require.

You must be logged in to reply to this topic.