diff --git a/Module/BrocadeICX/Core/New-ICXSession.ps1 b/Module/BrocadeICX/Core/New-ICXSession.ps1 index a0b7161..f013fa2 100644 --- a/Module/BrocadeICX/Core/New-ICXSession.ps1 +++ b/Module/BrocadeICX/Core/New-ICXSession.ps1 @@ -1,7 +1,7 @@ ############################################################################################################### # Language : PowerShell 4.0 # Filename : New-ICXSession.ps1 -# Autor : BornToBeRoot (https://github.com/BornToBeRoot) +# Author : BornToBeRoot (https://github.com/BornToBeRoot) # Description : Create a new Brocade ICX sessions over SSH # Repository : https://github.com/BornToBeRoot/PowerShell_BrocadeICX ############################################################################################################### @@ -24,8 +24,7 @@ https://github.com/BornToBeRoot/PowerShell_BrocadeICX/blob/master/Documentation/Function/New-ICXSession.README.md #> -function New-ICXSession -{ +function New-ICXSession { [CmdletBinding()] param( [Parameter( @@ -43,24 +42,26 @@ function New-ICXSession [Parameter( Position=2, Mandatory=$false, - HelpMessage='Credentials to authenticate agains a Brocade ICX Switch (SSH connection)')] + HelpMessage='Credentials to authenticate against a Brocade ICX Switch (SSH connection)')] [System.Management.Automation.PSCredential] [System.Management.Automation.CredentialAttribute()] $Credential ) - Begin{ - + Begin { + # If FIPS is enabled, exit with error + if ((Get-ItemPropertyValue -Path HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy -Name Enabled) -eq 1) { + throw "FIPS is enabled. FIPS must be disabled to establish SSH connection." + } } - Process{ + Process { # If no credentials are submitted by parameter, prompt the user to enter them - if($Credential -eq $null) - { - try{ + if ($Credential -eq $null) { + try { $Credential = Get-Credential $null } - catch{ + catch { throw "Entering credentials has been canceled by user. Can't establish SSH connection without credentials!" } } @@ -68,17 +69,14 @@ function New-ICXSession Write-Verbose -Message "Accept key is set to: $AcceptKey" # Create a new Brocade ICX session for each Switch - foreach($ComputerName2 in $ComputerName) - { + foreach ($ComputerName2 in $ComputerName) { Write-Verbose -Message "Create new SSH session for ""$ComputerName2""." - try{ - if($AcceptKey) - { + try { + if ($AcceptKey) { $Created_SSHSession = New-SSHSession -ComputerName $ComputerName2 -Credential $Credential -AcceptKey -ErrorAction Stop } - else - { + else { $Created_SSHSession = New-SSHSession -ComputerName $ComputerName2 -Credential $Credential -ErrorAction Stop } @@ -89,7 +87,7 @@ function New-ICXSession Write-Verbose -Message "Creating shell stream for ""$ComputerName2""..." $SSHStream = $SSHSession.Session.CreateShellStream("dumb", 0, 0, 0, 0, 1000) } - catch{ + catch { Write-Error -Message "$($_.Exception.Message)" -Category ConnectionError continue } @@ -105,7 +103,7 @@ function New-ICXSession Stream = $SSHStream } - # Set the default parameter set + # Set the default parameter set $ICXSession.PSObject.TypeNames.Insert(0,'BrocadeICX.ICXSession') $DefaultDisplaySet = 'SessionID', 'ComputerName', 'AccessMode' $DefaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet('DefaultDisplayPropertySet',[string[]]$DefaultDisplaySet) @@ -126,7 +124,7 @@ function New-ICXSession } } - End{ + End { } } \ No newline at end of file