Best Practices

This area describes common mistakes that can be made during application package creation.

Use Single Quotes instead of Double Quotes

  • Wrong
[Parameter(Mandatory)]
[ValidateSer("Splunk","Elasticsearch")]
[string]$Backend,
  • Correct
[Parameter(Mandatory)]
[ValidateSer('Splunk','Elasticsearch')]
[string]$Backend,

Space between Validation Options

  • Wrong
[Parameter(Mandatory)]
[ValidateSer('TCP', 'HTTP', 'Console')]
[string]$Protocol,
  • Correct
[Parameter(Mandatory)]
[ValidateSer('TCP','HTTP','Console')]
[string]$Protocol,

Set Comma after the Last Parameter

  • Wrong
Param (
    [Parameter(Mandatory=$false)]
    [ValidateSet('Install','Uninstall')]
    [string]$DeploymentType = 'Install',
    [Parameter(Mandatory=$false)]
    [ValidateSet('Interactive','Silent','NonInteractive')]
    [string]$DeployMode = 'Interactive',
    [Parameter(Mandatory=$false)]
    [switch]$AllowRebootPassThru = $false,
    [Parameter(Mandatory=$false)]
    [switch]$TerminalServerMode = $false,
    [Parameter(Mandatory=$false)]
    [switch]$DisableLogging = $false,
)
  • Correct
Param (
    [Parameter(Mandatory=$false)]
    [ValidateSet('Install','Uninstall')]
    [string]$DeploymentType = 'Install',
    [Parameter(Mandatory=$false)]
    [ValidateSet('Interactive','Silent','NonInteractive')]
    [string]$DeployMode = 'Interactive',
    [Parameter(Mandatory=$false)]
    [switch]$AllowRebootPassThru = $false,
    [Parameter(Mandatory=$false)]
    [switch]$TerminalServerMode = $false,
    [Parameter(Mandatory=$false)]
    [switch]$DisableLogging = $false
)