This script gets a count of the total mailboxes under management for each one of your tenants that you are a delegated administrator for in Office 365.  This is especially useful if you are a Microsoft partner and someone asks you "how many mailboxes are we responsible for?"  The exported CSV displays the domain name and the number of mailboxes associated with that domain.



Function Get-PartnerMailboxes 
        [Parameter(Mandatory = $True)] 
        [PSCredential]$Credential = (Get-Credential), 
        [Parameter(Mandatory = $True)] 
    Import-Module MSOnline 
    Connect-MsolService -Credential $Credential 
    $clients = (Get-MSOLPartnerContract) 
    $tenants = $clients.tenantid 
    ForEach ($Tenant in $Tenants) 
        $Users = Get-MsolUser -TenantId $Tenant| Where-Object {$_.IsLicensed -eq $True} 
        $UPN = $Users[0].UserPrincipalName 
        $Domain = $UPN.Split(‘@’) 
        $Properties = @{‘Licensed Users’ = $Users.Count; 
            ‘Domain’ = $Domain[1]; 
        $PropsObject = New-Object -TypeName PSObject -Property $Properties 
        $PropsObject | Export-CSV -Path $Path -NoTypeInformation -Append