Batch Update vSphere tags with Rubrik SLA Info

Batch Update vSphere tags with Rubrik SLA Info

Guess I should start with why. This was written so VM owners can check what types of backups they should expect. This avoids adding a ton of people as rubrik users.

First install the community supported Rubrik Powershell module.

Run powershell.exe

Install-Module -Name Rubrik -Scope CurrentUser

Get connected and dump out your Bronze, Silver, and Gold SLA machines.  This assumes you are using default SLAs.

Make sure you update the two variables at the top to make your environment

$RubrikURL = RUBRIK-URL.DOMAIN.COM
$WorkingDir = ~\Desktop\RubrikVMs.csv

connect-Rubrik $RubrikURL
$data = Get-RubrikVM -SLA Bronze | Select-Object name,moid,effectiveSladomainname
$data += Get-RubrikVM -SLA Silver | Select-Object name,moid,effectiveSladomainname
$data += Get-RubrikVM -SLA Gold | Select-Object name,moid,effectiveSladomainname
$data | export-csv $WorkingDir

Update your vSphere VMs with the backup status. I build out my code in excel and then execute it with PowerCLI.

$vCenterURL = VCENTER-URL.DOMAIN.COM

## Excel code to build your PowerCLI.
=CONCATENATE("Get-VM -id VirtualMachine-",B2," -name """,A2,""" | New-TagAssignment –Tag ",C2)
## Example of the completed code
connect-viserver $vCenterURL
Get-VM -id VirtualMachine-vm-123 -name "VirtualMachineName" | New-TagAssignment –Tag Bronze

Run the code created from excel, and you’ve updated all your machines. I find VMs using both the ID and the name, because you could get duplicates when running multiple vCenters. The absolute best way would be to use the hashed ID and/or the unique vCenter ID.

I’ll have to do this exercise again later, and I’ll have to make sure VMs that have been removed from SLA are covered. This is just the initial code.

Improvements for later

  • Use more unique VM identification.
  • pull back VMs that are not covered by SLA and make sure they are updated too.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s