Rubrik prides itself on delivering an API-first architecture in which anything that can be done within the user interface can also be accomplished through an API request. This design brings flexibility to our customers, extending Rubrik Cloud Data Management functionality directly into their automation workflows, offering them choice around how they would like to consume Rubrik. We’ve taken this approach one step further by providing the ability to customize exactly how our PowerShell module acts and performs. Customers can now take advantage of module options and default parameter values with the addition of a user-based options file utilized by the module.
Let’s dive into each option available.
Default Parameter Values
Customers can now define default values to any of the parameters within SDK by using these new cmdlets:
Get-RubrikModuleDefaultParameter
Set-RubrikModuleDefaultParameter
Remove-RubrikModuleDefaultParameter
These default values are then applied globally across all the PowerShell module cmdlets. For example, the PrimaryClusterId parameter is present on a wide range of cmdlets within the Rubrik SDK. Rather than constantly providing this value manually during cmdlet execution, a default value could be sent automatically by executing the following code:
Set-RubrikModuleDefaultParameter -ParameterName PrimaryClusterId -ParameterValue “local”
As shown below, once set, the local value will be sent to any Rubrik cmdlet that supports the PrimaryClusterId parameter. In this case, we are running the Get-RubrikSLA cmdlet.
![img](/content/dam/rubrik/blog/screenshots/products-solutions/Primary-Cluster_PowerShell-Rubrik.png)
If another value for PrimaryClusterId is desired, the default value can be overridden by explicitly naming the cluster using a parameter:
Get-RubrikSLA -PrimaryClusterId ‘11111-22222-33333-44444-55555’
And in the event that a default is no longer required, it can be removed utilizing the Remove-RubrikModuleDefaultParameter cmdlet:
Remove-RubrikModuleDefaultParameter -ParameterName PrimaryClusterId
While PowerShell’s global $PSDefaultParameterValues hashtable is used to store and apply these default values, they are also stored within the new rubrik_sdk_for_powershell_options.json file in the user’s $home directory. This allows for two very important features:
- While $PSDefaultParameterValues is session-based, the default values are able to persist by loading them from the options file each time the Rubrik module is imported.
- Alternatively, the options file can be modified directly, adding, removing or modifying any default parameter values manually. These changes will then be applied by either re-importing the module or executing Set-RubrikModuleDefaultParameter -Sync
Module Options
The second type of customizations available within the Rubrik SDK for PowerShell are module options. Module options, like default parameter values, are stored within the same configuration file but are designed to provide more choice around how the module works, rather than what parameter values are applied. To modify a module option, use the Set-RubrikModuleOption cmdlet, and to retrieve configured options, use the Get-RubrikModuleOption. However, unlike default parameter values, there is no way to remove a module option, as these are global configurations utilized within the module code and need to be present. If you remove a module option manually from the file, it will simply be recreated with a default value upon the next module import.
Today we have two module options available: ApplyDefaultViewDefinitions and CredentialPath.
AppyDefaultViewDefinitions
This module option controls whether or not custom view definitions are applied to the output of a cmdlet. Beginning with PowerShell module version 5.0.1, the amount of information displayed about a given object was limited utilizing custom view definitions. While this helps in terms of esthetics, there may be scenarios in which you want to view all of the object properties rather than our custom list. As shown below, simply running the Set-RubrikModuleOption -OptionName ApplyCustomViewDefinitions -OptionValue False cmdlet allows us to toggle whether these view definitions are applied or not.
![img](/content/dam/rubrik/blog/screenshots/products-solutions/Get-Rubrik-SLA_PowerShell.png)
CredentialPath
The CredentialPath option allows you to specify a path to a valid Common Language Infrastructure XML-based file (CLIXML) containing an encrypted credential object. When set, the module uses the credentials within the file when executing the Connect-Rubrik cmdlet, eliminating the need to manually pass credentials, use API tokens, or enter a username and password. Simply export a credential object to a CLIXML file, then set the CredentialPath option to the full path of that file. When Connect-Rubrik is called without specifying any credential, username/password, or API token, the default credentials are utilized.
![img](/content/dam/rubrik/blog/screenshots/products-solutions/Connect-Rubrik_PowerShell.png)
Having complete control over how the module works and the ability to set default parameter values that persist across PowerShell sessions not only saves you valuable time but also simplifies the process of interacting with Rubrik through PowerShell. If you would like to learn more about the Rubrik SDK for PowerShell, you can find Quickstart guides, videos, and all documentation in the project’s GitHub repository.
Are there any options you would like to see within the Rubrik SDK for PowerShell? Leave us a note on GitHub. We welcome any feedback, comments, enhancements or issues!