Skip to content

rubrikinc/rubrik-powershell-sdk

Repository files navigation

Rubrik Security Cloud PowerShell Module and SDK

The Rubrik Security Cloud PowerShell module:

  1. Makes it easy to work with RSC from the command line
  2. Acts as an SDK to provide access to the RSC API for custom scripting

(For the community CDM SDK for PowerShell, please see: github.com/rubrikinc/rubrik-sdk-for-powershell)

Support

Rubrik supports the commands and general functionality of this project. Rubrik cannot support custom script logic.

While this module may work with PowerShell 5.x, we recommend PowerShell >= 7.0. When troubleshooting, the first recommendation will be to upgrade from 5.x.

To give feedback on this project, open a new discussion.

🔨 Installation

Visit the Rubrik Developer Center PowerShell documentation for official installation instructions.

Advanced: Installing from Source

While we recommend using the PowerShell Gallery to install, advanced users may install the module from source.

Start by cloning the repo:

git clone [email protected]:rubrikinc/rubrik-powershell-sdk.git
cd rubrik-powershell-sdk

Then install the module from local sources:

./Utils/Import-RscModuleFromLocalOutputDir.ps1

At this point you can follow the Connecting to RSC instructions on the Developer Center.

⌛ Module Version vs API version

Once connected, check that your version of the module is not too far off from the version of the API server. Run:

PS> Get-RscVersion

SdkSchemaVersion ServerVersion
---------------- -------------
v20230524-16     v20230524-16

If your module version is too old, you will see a warning. You can still use the module, but you may not be able to use the latest features, and you may see some deprecation errors in your scripts. The module is generally backward compatible for a limited time. If you see deprecation errors when running your scripts, upgrade your module to the latest version as soon as possible.

🏃 Running commands

You can then run any of the commands in the module, for example, to retrieve the current account info:

Get-RscAccount
Get-RscAccount -Detail
(Get-RscAccount).AccountId

To list clusters:

$c=Get-RscCluster
$c # show all clusters
$c.Count # show number of clusters
$c[0] # show first cluster
$c.id # list cluster ids

To run raw GraphQL queries:

Invoke-Rsc -GqlQuery "query accountSettings{accountSettings{isEulaAccepted}}"

$vms=(Invoke-Rsc -GqlQuery 
  "query GetVsphereVmList{vSphereVmNewConnection{nodes{id name}}}").Nodes

To see all cmdlets in the module:

(Get-Module RubrikSecurityCloud).ExportedCommands.Keys | Sort-Object

🔌 Disconnecting

Then to disconnect:

Disconnect-Rsc

It is good practice and recommended to finish your scripts with Disconnect-Rsc. Note however that it is not strictly necessary, as the connection will be closed automatically when the session ends.

Learning More

👉 Start with the RSC PowerShell Module Developer Manual. Once you've covered the basics on this page, the developer manual will teach you how to use the module to build your own scripts.

It refers to samples that demonstrate how to use the module; you can also peruse the samples directly.

Another great way to learn about the module is to look at its end-to-end (e2e) tests: tests/e2e

GraphQL schema reference: