Skip to content

Commit

Permalink
Merge pull request #7 from alagoutte/powershell-6
Browse files Browse the repository at this point in the history
Add PowerShell 6 (Core) support
  • Loading branch information
alagoutte authored Mar 15, 2019
2 parents 984b3ad + 4720b90 commit 5a7f119
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
5 changes: 3 additions & 2 deletions PowerArubaCX/Private/RestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ function Invoke-ArubaCXRestMethod {

$Server = ${DefaultArubaCXConnection}.Server
$headers = ${DefaultArubaCXConnection}.headers
$invokeParams = ${DefaultArubaCXConnection}.invokeParams

$fullurl = "https://${Server}/${uri}"

$sessionvariable = $DefaultArubaCXConnection.session

try {
if ($body) {
$response = Invoke-RestMethod $fullurl -Method $method -body ($body | ConvertTo-Json) -Headers $headers -WebSession $sessionvariable
$response = Invoke-RestMethod $fullurl -Method $method -body ($body | ConvertTo-Json) -Headers $headers -WebSession $sessionvariable @invokeParams
}
else {
$response = Invoke-RestMethod $fullurl -Method $method -Headers $headers -WebSession $sessionvariable
$response = Invoke-RestMethod $fullurl -Method $method -Headers $headers -WebSession $sessionvariable @invokeParams
}
}

Expand Down
27 changes: 21 additions & 6 deletions PowerArubaCX/Public/Connection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function Connect-ArubaCX {
Process {


$connection = @{server = ""; session = ""}
$connection = @{server = ""; session = ""; invokeParams = ""}
$invokeParams = @{DisableKeepAlive = $false; UseBasicParsing = $true; SkipCertificateCheck = $SkipCertificateCheck}

#If there is a password (and a user), create a credentials
if ($Password) {
Expand All @@ -65,15 +66,28 @@ function Connect-ArubaCX {
$Credentials = Get-Credential -Message 'Please enter administrative credentials for your ArubaCX Switch'
}

#Allow untrusted SSL certificat and enable TLS 1.2 (needed by ArubaCX)
Set-ArubaCXCipherSSL
if ( $SkipCertificateCheck ) {
Set-ArubaCXuntrustedSSL
if ("Desktop" -eq $PSVersionTable.PsEdition) {
#Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5)
$invokeParams.remove("SkipCertificateCheck")
} else { #Core Edition
#Remove -UseBasicParsing (Enable by default with PowerShell 6/Core)
$invokeParams.remove("UseBasicParsing")
}

#for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust (needed/recommanded by ArubaCX)
if ("Desktop" -eq $PSVersionTable.PsEdition) {
#Enable TLS 1.1 and 1.2
Set-ArubaCXCipherSSL
if ($SkipCertificateCheck) {
#Disable SSL chain trust...
Set-ArubaCXuntrustedSSL
}
}

$postParams = @{username = $Credentials.username; password = $Credentials.GetNetworkCredential().Password}
$url = "https://${Server}/rest/v1/login"
try {
Invoke-RestMethod $url -Method POST -Body $postParams -SessionVariable arubacx | Out-Null
Invoke-RestMethod $url -Method POST -Body $postParams -SessionVariable arubacx @invokeParams | Out-Null
}
catch {
Show-ArubaCXException $_
Expand All @@ -82,6 +96,7 @@ function Connect-ArubaCX {

$connection.server = $server
$connection.session = $arubacx
$connection.invokeParams = $invokeParams

set-variable -name DefaultArubaCXConnection -value $connection -scope Global

Expand Down

0 comments on commit 5a7f119

Please sign in to comment.