VMware Cloud Community
jkb5054
Contributor
Contributor
Jump to solution

Vcloud PowerCLI - Email whole Org

Hi CLIers.

In vclouds UI we see there is a button to email all available email addresses in that certain vCloud Org.

Is there some call that can be made from PowerCLI to perform this Action?

Say I want to notify how a whole Org that they have X number of VMs.

Thanks for your help in advance,

-Joel

Reply
0 Kudos
1 Solution

Accepted Solutions
jake_robinson_b
Hot Shot
Hot Shot
Jump to solution

It appears the email function is not in the API, but the request is fairly easy to do without sending an email through the API.

1. Get all users and vapps in Org.

2. For each of the users, figure out how many VMs they have in vApps they own

3. Send an email.

Here's some code!

$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 "mail.example.com" -To $user.email -From "PowerCLI" -Body $mailbody            
            
}
Jake Robinson VCP, vExpert - geekafterfive.com - Twitter: @jakerobinson

View solution in original post

Reply
0 Kudos
1 Reply
jake_robinson_b
Hot Shot
Hot Shot
Jump to solution

It appears the email function is not in the API, but the request is fairly easy to do without sending an email through the API.

1. Get all users and vapps in Org.

2. For each of the users, figure out how many VMs they have in vApps they own

3. Send an email.

Here's some code!

$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 "mail.example.com" -To $user.email -From "PowerCLI" -Body $mailbody            
            
}
Jake Robinson VCP, vExpert - geekafterfive.com - Twitter: @jakerobinson
Reply
0 Kudos