rubrik-sdk-for-powershell
rubrik-sdk-for-powershell copied to clipboard
Connect-Rubrik with serviceaccount fails on Windows Powershell 5.1
Current Behavior:
Connect-Rubrik -Server '<some server>' -Id '<rubrik serviceaccount>' -Secret '<rubrik secret>'
fails on Windows Powershell 5.1, using Rubrik Powershell module 6.0.1
Invoke-RestMethod : A parameter cannot be found that matches parameter name 'SkipCertificateCheck'.
At C:\Program Files\WindowsPowerShell\Modules\Rubrik\6.0.1\Public\Connect-Rubrik.ps1:160 char:43
+ $response = Invoke-RestMethod @RestSplat -Verbose
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
The variable cannot be validated because the value is not a valid value for the Token variable.
At C:\Program Files\WindowsPowerShell\Modules\Rubrik\6.0.1\Public\Connect-Rubrik.ps1:161 char:13
+ $Token = $response.token
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [], ValidationMetadataException
+ FullyQualifiedErrorId : ValidateSetFailure
Expected Behavior:
Should work on Windows Powershell 5.1
Steps to Reproduce:
Please provide detailed steps for reproducing the issue.
Open a Windows Powershell 5.1 session Invoke the command as specified in 'Current Behavior'
Context:
na
Failure Logs
na
Sugested change Modify Connect-Rubrik.ps1 to make it Windows Powershell 5.1 compatible:
Replace
# retrieve bearer token from service account endpoint
$RestSplat = @{
Method = 'Post'
ContentType = "application/json"
URI = "[https://$Server/api/v1/service_account/session](https://%24server/api/v1/service_account/session)"
SkipCertificateCheck = $true
Body = @{
serviceAccountId = "$($Id)"
secret = "$($Secret)"
} | ConvertTo-Json
}
By
# retrieve bearer token from service account endpoint
$RestSplat = @{
Method = 'Post'
ContentType = "application/json"
URI = "[https://$Server/api/v1/service_account/session](https://%24server/api/v1/service_account/session)"
Body = @{
serviceAccountId = "$($Id)"
secret = "$($Secret)"
} | ConvertTo-Json
}
if (Test-PowerShellSix) {
$RestSplat.Add('SkipCertificateCheck',$true)
}
I can confirm this issue in my environment. No errors when executing in Powershell v7.2.8 but receive the same errors using Powershell v5.1.19041.2364
Experiencing the same issue with Windows Powershell 5.1. I think another approach is to make the SkipCertificateCheck a switch parameter to opt into rather than it being hard coded. In my environment all the clusters have CA signed certs so I don't want to necessarily ignore the certificate checks when using PS Core either.
Code for a fix for this has been merged.