Updating VM Annotation Attributes from Excel

Previous post was about backing up the VM description fields for a later restore just in case you planned a migration on which theses fields might be lost. Now let’s say we build a simple excel file with these values or you’ve just run the RVtools and want to use that reporting format later to restore your annotations.

Excel file sample:

Name Disks ProjectName Responsible Service
VM1 15GB 30GB Project Name 1 Responsible’s Name 1 Service Name 1
VM2 15GB 20GB 90GB 75GB 30GB Project Name 2 Responsible’s Name 2 Service Name 2
VM3 15GB 5GB Project Name 3 Responsible’s Name 3 Service Name 3
VM4 15GB 10GB Project Name 4 Responsible’s Name 4 Service Name 4

First, save XLS/XLSX file to a CSV format file named :  VMFieldReport.txt

##########################################################
# Name: WriteVMDescriptions
# Desc: Imports the VM annotation
# Date: 24/01/2013
# Auth: Alberto Ruiz
# https://virtualpad.wordpress.com
##########################################################

$FileList = "VMFieldReport.txt"

$VMList=Import-CSV $FileList

	ForEach($Line in $VMList)

		{
                        Get-Vm $Line.Name | Set-CustomField -name "Disks Used" -Value $Line.Disks
			Get-Vm $Line.Name | Set-CustomField -name "Project" -Value $Line.Project
			Get-Vm $Line.Name | Set-CustomField -name "Responsible" -Value $Line.Responsible
			Get-Vm $Line.Name | Set-CustomField -name "Service" -Value $Line.Service

		}

Ideally would be adding a new loop for every field and retrieve fieldname and fieldData. I’ll update my whislist 🙂

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s