Tuesday, March 31, 2009

Update Notes field for all VM in your Organisation

The Systems Administration team had been assigned the task of updating all VM guest machines with a description. This would allow us to have an idea of who owned and what a server did.

I thought this should easy enough to achieve a powershell script but I then released I could do this in 2 lines.

$vminfo = import=csv c:\powershell\vminfo.csv
$vminfo |ForEach-Object {set-vm $_.vmserver -Description $_.vmdescription -confirm:$false}

First you'll need CSV of the VM servernames and descriptions
example of vminfo.CSV

Vmserver,VMDescription
server1,Server owned by:Mr T VMdescription goes here
server2,Server owned by:Mr T VMdescription goes here

$vminfo = import=csv c:\powershell\vminfo.csv

In the first line of the command, the Import-CSV cmdlet is used to retrieve the saved object
representation from thevminfo.csv file, create corresponding objects and store them in the $vminfo variable.

$vminfo |ForEach-Object {set-vm $_.vmserver -Description $_.vmdscription -confirm:$false}

The secondline use a Foreach loop to set the description of the server. $vminfo is now object you can play with.

$_.Vmserver and $_.VMDescription values come from the header line of the CSV file.

Foreach-object ( i.e each line in vminfo.csv) do the set-vm cmdlet. -confirm:$file supresses confirmation.

/ Steve D

No comments:

Post a Comment