-
- Enthusiast
- Posts: 95
- Liked: 5 times
- Joined: Oct 17, 2015 3:32 pm
- Full Name: Stuart Little
- Location: Canada
- Contact:
Script to export and email custom attribute ...
Guys, have custom attribute in vCenter that we use to write to if the backup was successful.
We'd like to export the contents of that list to a CSV and email it out to our Ops guys daily.
Does anyone know of how we can do that...
TIA
We'd like to export the contents of that list to a CSV and email it out to our Ops guys daily.
Does anyone know of how we can do that...
TIA
-
- Enthusiast
- Posts: 95
- Liked: 5 times
- Joined: Oct 17, 2015 3:32 pm
- Full Name: Stuart Little
- Location: Canada
- Contact:
Re: Script to export and email custom attribute ...
I have something like this ...
It gives me the output.. but not the guestname.
Thoughts??
Code: Select all
Get-VM -Name *>.CustomFields
Thoughts??
-
- Veeam Software
- Posts: 649
- Liked: 170 times
- Joined: Dec 10, 2012 8:44 am
- Full Name: Nikita Efes
- Contact:
Re: Script to export and email custom attribute ...
It is doable with VMware PowerCLI, I've created some short sample to start with:
Code: Select all
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer <servername> -user <username> -password <pwd>
$vms = Get-VM -Name <*mask*>
$annotations = @{}
foreach ($vm in $vms) {$annotations[$vm] = (Get-Annotation -CustomAttribute <name of attribute> -Entity $vm).Value}
Send-MailMessage -Body ($annotations | Out-String) -From <backupadmin> -SmtpServer <yourserver.com> -Subject "B&R result" -To <address list>
-
- Enthusiast
- Posts: 95
- Liked: 5 times
- Joined: Oct 17, 2015 3:32 pm
- Full Name: Stuart Little
- Location: Canada
- Contact:
Re: Script to export and email custom attribute ...
After a bit of searching. I got what was looking for...
Code: Select all
$Report = @()
Get-VM | foreach{
$Summary = "" | Select VM
$Summary.VM = $_.Name
$_ | Get-Annotation | foreach{
Add-Member -InputObject $Summary -MemberType NoteProperty -Name $_.Name -Value $_.Value
}
$Report += $Summary
}
$Report | Export-Csv -Path Annotations.csv -Delimiter ";" -NoTypeInformation
-
- Enthusiast
- Posts: 95
- Liked: 5 times
- Joined: Oct 17, 2015 3:32 pm
- Full Name: Stuart Little
- Location: Canada
- Contact:
Re: Script to export and email custom attribute ...
nefes wrote:It is doable with VMware PowerCLI, I've created some short sample to start with:Code: Select all
Add-PSSnapin VMware.VimAutomation.Core Connect-VIServer <servername> -user <username> -password <pwd> $vms = Get-VM -Name <*mask*> $annotations = @{} foreach ($vm in $vms) {$annotations[$vm] = (Get-Annotation -CustomAttribute <name of attribute> -Entity $vm).Value} Send-MailMessage -Body ($annotations | Out-String) -From <backupadmin> -SmtpServer <yourserver.com> -Subject "B&R result" -To <address list>
Thank you sir... I'll try this too.
-
- Enthusiast
- Posts: 95
- Liked: 5 times
- Joined: Oct 17, 2015 3:32 pm
- Full Name: Stuart Little
- Location: Canada
- Contact:
Re: Script to export and email custom attribute ...
What value to do I put for .. as I want to search all guests ?Jack1874 wrote:
Thank you sir... I'll try this too.
Code: Select all
$vms = Get-VM -Name <*mask*>
-
- Veeam Software
- Posts: 649
- Liked: 170 times
- Joined: Dec 10, 2012 8:44 am
- Full Name: Nikita Efes
- Contact:
Re: Script to export and email custom attribute ...
You can use get-vm without parameters if you want all vms from connected host.
As for guest name, you can use $vm.guest.hostname
As for guest name, you can use $vm.guest.hostname
-
- Enthusiast
- Posts: 95
- Liked: 5 times
- Joined: Oct 17, 2015 3:32 pm
- Full Name: Stuart Little
- Location: Canada
- Contact:
Re: Script to export and email custom attribute ...
Got it..thanks. It works great.
Is it possible to dump the data into a CSV .. and then email the CSV?
Is it possible to dump the data into a CSV .. and then email the CSV?
-
- Veeam Software
- Posts: 649
- Liked: 170 times
- Joined: Dec 10, 2012 8:44 am
- Full Name: Nikita Efes
- Contact:
Re: Script to export and email custom attribute ...
Yes, I've modified getting annotations and exporting to CSV, so you can see guest name and backup result in csv:
Code: Select all
$annotations = @{}
foreach ($vm in $vms) {$annotations[$vm.guest.hostname] = (Get-Annotation -CustomAttribute <name of attribute> -Entity $vm).Value}
$annotations.GetEnumerator() | Select-Object -Property @{n= 'Guest Name'; e = {$_.Name}}, @{n ='BackupResult'; e = {$_.Value}} | Export-Csv -Path <temp csv path> -NoTypeInformation
Send-MailMessage -Body ("see attach") -From <> -SmtpServer <> -Subject "B&R result" -To <> -Attachments <temp csv path>
-
- Enthusiast
- Posts: 95
- Liked: 5 times
- Joined: Oct 17, 2015 3:32 pm
- Full Name: Stuart Little
- Location: Canada
- Contact:
Re: Script to export and email custom attribute ...
Perfect.. all tested and works as required.
Thanks for you help.
Thanks for you help.
Who is online
Users browsing this forum: masahide.k and 13 guests