From 4800cc6564a2ef1889f70c73b2331c8a4c6ab0b9 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 21 Jul 2021 23:02:18 +0200 Subject: [PATCH] Connect: Add SkipCertificateCheck parameter (for PS5 and Core) Also enable TLS 1.1 and 1.2 for PS5 --- Functions/Setup/Connect-NetboxAPI.ps1 | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Functions/Setup/Connect-NetboxAPI.ps1 b/Functions/Setup/Connect-NetboxAPI.ps1 index 4244f2a..6bc0d03 100644 --- a/Functions/Setup/Connect-NetboxAPI.ps1 +++ b/Functions/Setup/Connect-NetboxAPI.ps1 @@ -49,7 +49,10 @@ [Parameter(ParameterSetName = 'URI', Mandatory = $true)] - [string]$URI + [string]$URI, + + [Parameter(Mandatory = $false)] + [switch]$SkipCertificateCheck = $false ) if (-not $Credential) { @@ -64,7 +67,22 @@ } } - $null = Set-NetboxCredential -Credential $Credential + $invokeParams = @{ SkipCertificateCheck = $SkipCertificateCheck; } + + if ("Desktop" -eq $PSVersionTable.PsEdition) { + #Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5) + $invokeParams.remove("SkipCertificateCheck") + } + + #for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust + if ("Desktop" -eq $PSVersionTable.PsEdition) { + #Enable TLS 1.1 and 1.2 + Set-NetboxCipherSSL + if ($SkipCertificateCheck) { + #Disable SSL chain trust... + Set-NetboxuntrustedSSL + } + } switch ($PSCmdlet.ParameterSetName) { 'Manual' { @@ -80,8 +98,10 @@ } $null = Set-NetboxHostName -Hostname $uriBuilder.Host + $null = Set-NetboxCredential -Credential $Credential $null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme $null = Set-NetboxHostPort -Port $uriBuilder.Port + $null = Set-NetboxInvokeParams -invokeParams $invokeParams try { Write-Verbose "Verifying API connectivity..."