GeekAfterFive

Infrastructure as Code

home

Emailing vCloud Organization Users

13 Jun 2012

a pictureA question popped in the vCloud PowerCLI forum the other day on how to use the "notify users" function in the vCloud Director Web UI through the vCloud API. While the functionality is not in the API, PowerCLI and Powershell make short work of it with the vCloud snap-in and Powershell's Send-MailMessage cmdlet. a picture The task in this case was to send an email to all Org users to remind them of the number of VMs they have in a particular organization. The following code could easily be adapted to show: Resource usage, IP addresses, OS usage, etc. Probably the most interesting thing I find about this code is that it can be used in either a systems admin role, or an organization admin role.
$mailServer = "mail.example.com"
$users = Get-CIUser # use -Org "OrgName" if connected to system Org
$VApps = Get-CIVApp # use -Org "OrgName" if connected to system Org

foreach ($user in $users)
{
 $counter = 0
 $ownerVApps = $VApps | where {$_.owner -eq $user}
 $vapps | ForEach-Object {$counter += $_.extensiondata.children.vm.count}

$mailbody = "Greetings, You currently have $counter virtual machines in Organization: $($user.Org)"

Send-MailMessage -SmtpServer $mailServer -To $user.email -From "PowerCLI@example.com" -Body $mailbody

}
 
comments powered by Disqus