3

Is it possible to determine if certain cmdlet has one exact parameter? For example if I work with Exchange server I know that web-access for devices is present since 2013 version. So before this version there are no related parameters in cmdlets. Is it possible to take a cmdlet, for example New-Mailbox and check if it has one exact parameter (that parameter would not exist for 2010 version and would for 2013+)?

0

3 Answers 3

2

The question is quite old, but still.. :) Try the code below to get list of available CmdLet parameters

$params = (Get-Command New-Mailbox).ParameterSets | Select -ExpandProperty Parameters
$params | ForEach {$_.Name}
Sign up to request clarification or add additional context in comments.

1 Comment

Great! Just my 2 Cents, that it displays the unique, alphabetically ordered parameters: $params | ForEach {$_.Name} | Sort-Object | Get-Unique
2

Pavel's answer is fine. This way is slightly shorter and easier to read:

(Get-Command cmdletName).Parameters['parameterName']

This example uses this to check the New-Mailbox cmdlet for the EnableRoomMailboxAccount parameter, which was added in Exchange Server 2013 (the scenario described in the question):

if((Get-Command New-Mailbox).Parameters['EnableRoomMailboxAccount']) {
    New-Mailbox -UserPrincipalName [email protected] `
        -Alias confroom1010 `
        -Name "Conference Room 1010" `
        -Room `
        -EnableRoomMailboxAccount $true `
        -RoomMailboxPassword (ConvertTo-SecureString -String P@ssw0rd -AsPlainText -Force)
}
else {
    New-Mailbox -UserPrincipalName [email protected] `
    -Alias confroom1010 `
    -Name "Conference Room 1010" `
    -Room
}

Comments

0

The PowerShell $args variable is an array of the parameters used in the call. You can use $args.Count to verify the desired parameter is there. You can also test against the value of the first parameter by using $args[0].

Mike

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.