Skip to content

Instantly share code, notes, and snippets.

@drew-russell
Created March 11, 2020 21:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drew-russell/afded9eba3351f2904bbd8070f00afb7 to your computer and use it in GitHub Desktop.
Save drew-russell/afded9eba3351f2904bbd8070f00afb7 to your computer and use it in GitHub Desktop.
Example Powershell script that calls the Rubrik CDM GraphQL Service
$NodeIP = ''
# Prompt for Rubrik cluster Username and Passwrod
$RubrikCredential = Get-Credential
$EncodedCredential = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($RubrikCredential.UserName + ':' + $RubrikCredential.GetNetworkCredential().Password))
$Headers = @{
'Content-Type' = 'application/json';
'Accept' = 'application/json';
'Authorization' = "Basic " + $EncodedCredential
}
$GraphQLServiceEndpoint = 'https://' + $NodeIP + '/api/internal/graphql'
$ClusterID = 'me'
$Payload = @{
"operationName" = "ClusterDetails";
"variables" = @{"clusterID" = 'me' };
"query" = "query ClusterDetails(`$clusterID: String!) {
cluster(id: `$clusterID) {
version
}
}"
}
$Response = Invoke-RestMethod -Method POST -Uri $GraphQLServiceEndpoint -Body $($Payload | ConvertTo-JSON -Depth 100) -Headers $Headers
Write-Output ($Response | ConvertTo-JSON -Depth 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment