Connect: Add SkipCertificateCheck parameter (for PS5 and Core)

Also enable TLS 1.1 and 1.2 for PS5
This commit is contained in:
Alexis La Goutte 2021-07-21 23:02:18 +02:00
parent 1a2484db2c
commit 4800cc6564

View file

@ -49,7 +49,10 @@
[Parameter(ParameterSetName = 'URI', [Parameter(ParameterSetName = 'URI',
Mandatory = $true)] Mandatory = $true)]
[string]$URI [string]$URI,
[Parameter(Mandatory = $false)]
[switch]$SkipCertificateCheck = $false
) )
if (-not $Credential) { 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) { switch ($PSCmdlet.ParameterSetName) {
'Manual' { 'Manual' {
@ -80,8 +98,10 @@
} }
$null = Set-NetboxHostName -Hostname $uriBuilder.Host $null = Set-NetboxHostName -Hostname $uriBuilder.Host
$null = Set-NetboxCredential -Credential $Credential
$null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme $null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme
$null = Set-NetboxHostPort -Port $uriBuilder.Port $null = Set-NetboxHostPort -Port $uriBuilder.Port
$null = Set-NetboxInvokeParams -invokeParams $invokeParams
try { try {
Write-Verbose "Verifying API connectivity..." Write-Verbose "Verifying API connectivity..."