I recently had 3 Rubrik customers asking for ways to automate protecting VMs by a means not available in the UI. Any use case is possible when you have an API first platform, so in this post I’m going to share with you the scripts I created for them.
The first request was a script to automatically protect VMs with an SLA domain based on a string within the VM name, because they had 1000s of VDI VMs with no consistent VM folder or tag. The second was a CSV list of VM and SLA names, with the VMs automatically protected based on the list. The third was to export a list of all VMs from Rubrik, edit the CSV output with the new SLA settings, then import to apply the new settings.
With all 3 they wanted to see what would happen first before applying the protection, with credentials saved securely so it could run headless on a schedule going forward. If you are thinking at this point, what about VM tags? I already shared that, you can find it here.
To get you started download the zip file below:
In the zip file you’ll find the following scripts:
- RubrikAutoVMProtectv1-ByVMName.ps1 – Finds the VMs with a matching string and protects them with the SLA specified.
- RubrikAutoVMProtectv1-ImportByName.ps1 – Imports any CSV using VMName and NewSLADomain columns to then apply the SLA.
- RubrikAutoVMProtectv1-Export.ps1 – Exports all the VMs that the Rubrik cluster can see to a CSV for configuration.
- RubrikAutoVMProtectv1-Import.ps1 – Imports the above CSV and applies the NewSLADomain specified. Also useful for making bulk SLA reassignments, and this can be used to explicitly set DoNotProtect on a VM by changing the NewSLADomain field to DoNotProtect.
With all 4 scripts configure the $RubrikCluster and $ScriptDirectory variables to match your environment and you are good to go. By default they all have $DryRunEnabled = $True to show you what they would do, change it to False to apply the SLAs defined.
Hope you found these useful. Happy scripting,