rubrikinc / rubrik-sdk-for-powershell

Rubrik Module for PowerShell
https://build.rubrik.com/sdks/powershell/
MIT License
102 stars 87 forks source link

Stop-RubrikManagedVolumeSnapshot & Start-RubrikManagedVolumeSnapshot service account issues on Powershell 7 #827

Open Gvangeystelen opened 1 year ago

Gvangeystelen commented 1 year ago

Current Behavior:

In Powershell 5 both cmdlets (Stop-RubrikManagedVolumeSnapshot & Start-RubrikManagedVolumeSnapshot) work without any issues.

To prepare for the switch to Rubrik Service accounts (instead of AD accounts) and the upgrade to latest Rubrik version we are modifying our Powershell scripts to work on Powershell 7. (This is a prerequisite for latest Rubrik version apparently.)

log in to Rubrik cluster (via service account and secret) works without issues, once authenticated I can also use Get-RubrikManagedVolume and get the properties back.

If I pipe this output to the Stop-RubrikManagedVolumeSnapshot cmdlet I get an error, likewise if I fill in the -id parameter manually

script for connection:

$body = @{
  serviceAccountId = $serviceAccountId
  secret = $secret
}
$bodyJson = $body | ConvertTo-Json 
$sessionURL = "https://$cluster/api/v1/service_account/session"
$Uri = [System.Uri]$sessionURL
$rubrikSession = Invoke-RestMethod -Method POST -Uri $Uri -Body $bodyJson -ContentType $type -SkipCertificateCheck

$rubrikConnection = @{
  api = 1
  server = $cluster
  token = $rubrikSession.token
  header = @{ 
    'Authorization' = "Bearer $($rubrikSession.token)"
  }
}

![RubrikModule](https://user-images.githubusercontent.com/124145761/216014821-28a2a634-cc61-4021-9019-545acde7e791.png)
![RubrikModule_2](https://user-images.githubusercontent.com/124145761/216017856-cea63092-cbc4-4417-9874-57b3d2f9a6d2.png)

Expected Behavior: Be able to stop or start a managed volume snapshot.

Steps to Reproduce:

Please provide detailed steps for reproducing the issue.

  1. Install Rubrik Powershell module on Powershell 7
  2. In Powershell 7 terminal: Connect to Rubrik server via the script above by using a service account and secret
  3. Once connected get properties of a managed volume via Get-RubrikManagedVolume and store this in a variable 4.View the output of the variable to confirm that we get properties back 5.Either pipe the output to Stop-RubrikManagedVolumeSnapshot or Start-RubrikManagedVolumeSnapshot or fill in the -id manually (visible in the properties of the variable)

Context:

Gvangeystelen commented 1 year ago

UPDATE : I got this working with the following workaround, : use solely the Rubrik API for these 2 cmdlets

Hopefully this is helpful for someone with the same issue: $serviceAccountId $secret $cluster

values are omitted for obvious reasons

Import-Module Rubrik 

$serviceAccountId=""
$secret=""
$cluster=""

$body = @{
  serviceAccountId = $serviceAccountId
  secret = $secret
}
$bodyJson = $body | ConvertTo-Json 
$sessionURL = "https://$cluster/api/v1/service_account/session"
$Uri = [System.Uri]$sessionURL
$rubrikSession = Invoke-RestMethod -Method POST -Uri $Uri -Body $bodyJson -ContentType $type -SkipCertificateCheck
$rubrikSessionHeader = @{'Authorization' = "Bearer $($rubrikSession.token)"}

$rubrikConnection = @{
  api = 1
  server = $cluster
  token = $rubrikSession.token
  header = @{ 
    'Authorization' = "Bearer $($rubrikSession.token)"
  }
}

#Get ManagedVolume properties
$ManagedVolume = Get-RubrikManagedVolume -name 'SQLBackups_XXX'

$ManagedVolumeId = $ManagedVolume.ID

#Check for propertyvalue that is true when MangedVolume is open
$Open=$ManagedVolume.PSobject.Properties | Where-Object {$_.Name -like "isWritable"}

# If open close the volume, else open the volume
if($Open.Value -eq "True")
{

$sessionURLCloseManagedVolume = "https://$cluster/api/v1/managed_volume/$ManagedVolumeId/end_snapshot"
$UriClose = [System.Uri]$sessionURLCloseManagedVolume
$bodyCloseJson = 
    @'
{
    "expiryDurationInMinutes": 0,
    "ownerId": "string",
    "refId": "string"
    },
"isAsync": true
}
'@
$rubrikSessionCloseManagedVolumeSnapshot = Invoke-RestMethod -Method POST -Uri $UriClose -Body $bodyCloseJson -ContentType $type -Headers $rubrikSessionHeader -SkipCertificateCheck

}else
{
#Open the specified managed volume for read/write operations
$sessionURLOpenManagedVolume = "https://$cluster/api/v1/managed_volume/$ManagedVolumeId/begin_snapshot"
$UriOpen = [System.Uri]$sessionURLOpenManagedVolume
$bodyOpenJson = 
    @'
{
    "expiryDurationInMinutes": 0,
    "ownerId": "string",
    "refId": "string"
    },
"isAsync": true
}
'@
$rubrikSessionOpenManagedVolumeSnapshot = Invoke-RestMethod -Method POST -Uri $UriOpen -Body $bodyOpenJson -ContentType $type -Headers $rubrikSessionHeader -SkipCertificateCheck

}
Disconnect-Rubrik -Confirm:$false
infraDaveLondon commented 1 year ago

bug is still active - the solution provided by [Gvangeystelen] worked for me. many thanks