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+)?
3 Answers
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}
1 Comment
pholpar
Great! Just my 2 Cents, that it displays the unique, alphabetically ordered parameters: $params | ForEach {$_.Name} | Sort-Object | Get-Unique
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
}