I would like to update the "Notes" section with host owner information, pulled from a cvs file (data is really in a mysql database, but i think it would be easier via a cvs..)
Can I use powercli to read the cvs file for a hostname, connect to VC and populate that info into the "Notes" field?
Thanks!
Afaik only guests have a Notes section, for ESX(i) hosts you can only define a custom attribute.
Try this
Connect-VIServer -server $vc New-CustomAttribute -Name "Owner" -TargetType "VMHost" Import-Csv "C:\owner-info.csv" | %{ Set-Annotation -Entity (Get-VMHost -Name $_.Hostname) -CustomAttribute "Owner" -Value $_.HostOwner }
It assumes you have a CSV file like this
Hostname,HostOwner esx1,user1 esx2,user2 ...
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, sometimes it gets confusing between "host", "guest", etc.
I have a cvs file with a hostname (dns name) of my running VMWare Guests machines, and the owners name.
I would like to script something that looks at the file, and updates the "Notes" section of each guests in my VC and include the owners name.
Thanks in advance!
Mike
A modification of the "who created that VM?" script http://www.virtu-al.net/2010/02/23/who-created-that-vm/ might do it, I'm just not that good...but I'm trying!
Ok, got it.
Try this (the CSV file has the same layout)
New-CustomAttribute -Name "Owner" -TargetType "VirtualMachine" -ErrorAction SilentlyContinue Import-Csv "C:\owner-info.csv" | %{ Set-CustomField -Name "Owner" -Value $_.HostOwner -Entity (Get-VM -Name $_.Hostname) }
I assume that the hostname in the CSV file corresponds with the name of the guest ?
The first line creates the new custom attribute.
If it already exists, the -ErrorAction parameter will suppress the error message and the script will continu.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect!
I am building a new CVS file now but my initial test was a huge success!
grazie!
wicked!