From 7826fae609d6037e9b26b28d846ec2867229d7a9 Mon Sep 17 00:00:00 2001 From: Michael Arranaga Date: Fri, 28 Sep 2018 15:28:39 -0500 Subject: [PATCH] Fixed optional parameter (#16) * Added logging and env variable * One more error checking * Updated reademe * Changed to an optional parameter --- ePOwerShell/Public/Set-ePOwerShellServer.ps1 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ePOwerShell/Public/Set-ePOwerShellServer.ps1 b/ePOwerShell/Public/Set-ePOwerShellServer.ps1 index 7a6c5b1..98fa050 100644 --- a/ePOwerShell/Public/Set-ePOwerShellServer.ps1 +++ b/ePOwerShell/Public/Set-ePOwerShellServer.ps1 @@ -45,13 +45,13 @@ function Set-ePOwerShellServer { [String] $Server, - [Parameter(Mandatory = $True, ParameterSetName = 'ManualEntry')] - [Int] - $Port, - [Parameter(Mandatory = $True, ParameterSetName = 'ManualEntry')] [System.Management.Automation.PSCredential] $Credentials, + + [Parameter(Mandatory = $False, ParameterSetName = 'ManualEntry')] + [Int] + $Port, [Parameter(ParameterSetName = 'Env')] [String] @@ -101,16 +101,22 @@ function Set-ePOwerShellServer { $ePOwerShellVariables = @{ Server = $Settings.Server - Port = $Settings.Port Credentials = $Credentials } + + if ($settings.Port) { + [void]$ePOwerShellVariables.Add("Port", $Settings.Port) + } } 'ManualEntry' { $ePOwerShellVariables = @{ Server = $Server - Port = $Port Credentials = $Credentials } + + if ($Port) { + [void]$ePOwerShellVariables.Add("Port", $Port) + } } }