Hiding Parameters

by Nov 2, 2018

In the previous tip we explained how you can dump all the legal values for a PowerShell attribute. Today we’ll take a look at the [Parameter()] attribute and its value DontShow. Take a look at this function:

function Test-Something
{
    param
    (
        [string]
        [Parameter(Mandatory)]
        $Name,
        
        [Parameter(DontShow)]
        [Switch]
        $Internal
    )

    "You entered: $name"
    if ($Internal)
    {
        Write-Warning "We are in secret test mode!"
    }
} 

When you run the function, IntelliSense only exposes the -Name parameter. The -Internal switch parameter is not shown, however you can still use it. It is just a hidden parameter:

 
PS> Test-Something -Name tobias
You entered: tobias

PS> Test-Something -Name tobias -Internal
You entered: tobias
WARNING: We are in secret test mode!

Twitter This Tip! ReTweet this Tip!