Hi everyone,

Here my first post on our blog vBlog.nl. So the first blog is about the VMware DaaS REST API and how the send a mail with a usage report.
I will also provide you the different lines of code for DaaS 7 and 8. For DaaS 8 there is no REST API documentation available and you have to do it with the DaaS 7 version.

Why doing it via the API? In the service center you have the option to download a CSV…
Well normally your sales support colleagues do not have access to the DaaS service center, and the CSV does not contain the friendly names of the tenants. The second thing is that the CSV contains much more information then they need, and in the most cases you will get questions about that 🙂

Download CSV the GUI way:

  • Login to your “service center”
  • Go to configuration > standard capacity. Here you will find “Download Usage Report”

Lets do it the PowerShell way:

    Get a Daas usage report
    Get a Daas usage report and e-mail it to your colleagues
    Get a Daas usage report for DaaS 8
    Get-DaasUsageReport -Url -NewCredentials
   Inputs to this cmdlet (if any)
   Output from this cmdlet (if any)
   General notes
   The component this cmdlet belongs to
   The role this cmdlet belongs to
   The functionality that best describes this cmdlet
function Get-DaasUsageReport {
    param (
    begin {
        # Validate the input
            $uri = $url -as [System.URI]
            $UrlValidation = $uri.AbsoluteURI -ne $null -and $uri.Scheme -match 'https' -and $uri.ToString().StartsWith("https://")
                Write-Error "Input is not a valid URL, please Try again."
            } Else {
        # Trim ending slash
        If($url.EndsWith("/")) {
            $url = $url.Substring(0,$url.Length-1)
        #Triyng to store the password ad secure as possible
            if(!(Test-Path 'C:\Temp')){New-Item -Path 'c:\temp' -ItemType:Directory -Force | Out-Null}
            $Credential = (Get-Credential -Message "Enter credentials to be safely stored.") | Export-CliXml -Path C:\Temp\MyCredential.xml -Force
        try{$credential = Import-CliXml -Path C:\Temp\MyCredential.xml} catch {}
            $Credential = (Get-Credential -Message "Credentials cannot be found, you deen to add new ones ") | Export-CliXml -Path C:\Temp\MyCredential.xml -Force
        $domain,$username = $Credential.UserName.Split('\')
        $ww = $credential.GetNetworkCredential().password
        [xml]$xmlCreds = @"
        <DtCredentials type="CREDENTIALS">
        #clear credentials varaiable
        $credential = ''
        $username = ''
        $domain = ''
        $ww = ''
        # FIX: Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
        # When the portal has no certificate installed
        if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type) {
        $certCallback = @"
            using System;
            using System.Net;
            using System.Net.Security;
            using System.Security.Cryptography.X509Certificates;
            public class ServerCertificateValidationCallback
                public static void Ignore()
                    if(ServicePointManager.ServerCertificateValidationCallback ==null)
                        ServicePointManager.ServerCertificateValidationCallback +=
                                Object obj,
                                X509Certificate certificate,
                                X509Chain chain,
                                SslPolicyErrors errors
                                return true;
            Add-Type $certCallback
        function APIauthentication {
            param (
            $Headers = @{}
            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
            $creds = Invoke-WebRequest -uri "$url/dt-rest/v100/system/authenticate/credentials" -Body $body -Method Post -Headers $Headers
        . APIauthentication -daas $Url -body $xmlCreds
        #clear credentials varaiable
        $xmlCreds = ''
    process {
        $RawOrgs = Invoke-WebRequest -Uri "$url/dt-rest/v100/security/manager/organizations" -Method Get -Headers $Headers
        $XMLOrgs = [xml]$RawOrgs.Content
        $AllOrgNames = $XMLOrgs.List.DtOrganization | ? {$_.disabled -eq $false} | select name,id
        $TenantNameHash = @{}
        foreach ($org in $AllOrgNames){
        $TenantNameHash.Remove("Service Provider")
        $RawQuotas = Invoke-WebRequest -Uri "$url/dt-rest/v100/reporting/manager/consumedquota" -Method Get -Headers $Headers
        $XMLQuotas = [xml]$RawQuotas.Content
        $AllOrgQuotas = $XMLQuotas.list.DtDesktopModelUsageData | select orgid,NumVms,name
        $QuotaReport = @()
        foreach ($orgQ in $AllOrgQuotas) {
            $Tenant = $TenantNameHash.GetEnumerator() | %{$_ | ? {$_.value -eq $orgQ.orgId}}
            $hash = New-Object PSObject -property @{Tenant=$Tenant.Key;TenantId=$orgQ.orgId;DesktopModel=$orgQ.name[0];NumVms=$orgQ.numVms}
            $QuotaReport += $hash
    end {
        $Table = $QuotaReport | ConvertTo-Html | Out-String
        #mail body
        $MailBody = "
        Hi Colleagues,<br>
        Here is th DaaS usage report
        Kind Regards,<br>
        The DaaS team
        # Send the email
        $MailCred = (Get-Credential)
        $SmtpServer = "smtp.office365.com"
        $SmtpPort = 587
        $From = $MailCred.UserName
        $To = "user@company.ext","user2@company.ext"
        $cc = "team@company.ext"
        $currentMonth = Get-Date -UFormat %m
        $currentMonth = (Get-Culture).DateTimeFormat.GetMonthName($currentMonth)
        $Subject = "DaaS usage report $currentMonth"
        Send-MailMessage -smtpserver $smtpserver -from $from -to $to -Cc $cc -subject $subject -body $MailBody -BodyAsHtml -Credential $MailCred -Port $SmtpPort -UseSsl
. Get-DaasUsageReport -Url "https://siteurl.ext" -Verbose

 6,257 total views,  2 views today