Before you start...
Scenario
Option 1: Get Report for All Customers
Clear-Host Write-Progress -Id 1 -Activity "Get tenant list" -Status "Retrieving... this may take several minutes" $tenantList = Get-MsolpartnerContract -All | Format-Table -Property TenantID -AutoSize -HideTableHeaders | Out-file "C:\Scripts\TenantList.txt" (get-content "C:\Scripts\TenantList.txt") | where {$_ -ne ""} | out-file "C:\Scripts\TenantList.txt" $myTechNotOutput=@() $myAdminOutput =@() $myInvalidOutput =@() $inputFile = get-content "C:\Scripts\TenantList.txt" $totTenants = $inputfile.count foreach ($tenantItem in $inputFile) { $tenantCount = $tenantItem.readcount Write-Progress -Id 1 -Activity "Get tenant list" -Status "Completed" -PercentComplete 100 Write-Progress -Id 2 -Activity "Validating tenant list and retrieving data" -PercentComplete (($tenantCount/ $totTenants)*100) -CurrentOperation " processing $tenantCount of $totTenants" -status "Please wait" $Company = Get-MsolCompanyInformation -TenantID $tenantItem -ErrorAction SilentlyContinue If (!$?) { $objInvalid = New-Object system.object $objInvalid | Add-Member -Type NoteProperty -Name TenantID -value $tenantItem $myInvalidOutput += $objInvalid } Else { $Company = Get-MsolCompanyInformation -TenantID $tenantItem | Select DisplayName, @{Name='TechnicalNotificationEmails';Expression={[string]::join(";", ($_.TechnicalNotificationEmails))}} $InitialDomain = Get-MsolDomain -TenantID $tenantItem | where {$_.IsInitial -Eq $true} $CompanyAdmins = Get-MsolRoleMember -TenantID $tenantItem -roleobjectID 62e90394-69f5-4237-9190-012177145e10 $objTechNot = New-Object system.object $objTechNot | Add-Member -Type NoteProperty -Name TenantID -value $tenantItem $objTechNot | Add-Member -Type NoteProperty -Name CompanyName -value $Company.DisplayName $objTechNot | Add-Member -Type NoteProperty -Name OnMicrosoftDomain -value $InitialDomain.Name $objTechNot | Add-Member -Type NoteProperty -Name CompanyTechnicalNotificationEmails -value $Company.TechnicalNotificationEmails $myTechNotOutput += $objTechNot foreach($caItem in $CompanyAdmins) { $Email =Get-MsolUser -TenantID $tenantItem -ObjectID $caItem.ObjectID | Select UserPrincipalName, PhoneNumber, MobilePhone, @{Name='AlternateEmailAddresses';Expression={[string]::join(";", ($_.AlternateEmailAddresses))}} $objAdmin = New-Object system.object $objAdmin | Add-Member -Type NoteProperty -Name TenantID -value $tenantItem $objAdmin | Add-Member -Type NoteProperty -Name CompanyName -value $Company.DisplayName $objAdmin | Add-Member -Type NoteProperty -Name OnMicrosoftDomain -value $InitialDomain.Name $objAdmin | Add-Member -Type NoteProperty -Name AdminUserUPN -value $Email.UserPrincipalName $objAdmin | Add-Member -Type NoteProperty -Name AdminUserAltEmail -value $Email.AlternateEmailAddresses $objAdmin | Add-Member -Type NoteProperty -Name AdminUserPhone -value $Email.PhoneNumber $objAdmin | Add-Member -Type NoteProperty -Name AdminUserMobilePhone -value $Email.MobilePhone $myAdminOutput += $objAdmin } } } $myInvalidOutput | export-csv -Path "C:\Scripts\InvalidTenants.csv" -NoTypeInformation $myTechNotOutput | export-csv -Path "C:\Scripts\TechNotList.csv" -NoTypeInformation $myAdminOutput | export-csv -Path "C:\Scripts\CompanyAdminList.csv" -NoTypeInformation
Option 2: Get Report for Some Customers (provide list of TenantIDs)
Clear-Host Write-Progress -Id 1 -Activity "Get tenant list" -Status "Retrieving... this may take several minutes" $myTechNotOutput=@() $myAdminOutput =@() $myInvalidOutput =@() $inputFile = get-content "C:\Scripts\TenantList.txt" $totTenants = $inputfile.count foreach ($tenantItem in $inputFile) { $tenantCount = $tenantItem.readcount Write-Progress -Id 1 -Activity "Get tenant list" -Status "Completed" -PercentComplete 100 Write-Progress -Id 2 -Activity "Validating tenant list and retrieving data" -PercentComplete (($tenantCount/ $totTenants)*100) -CurrentOperation " processing $tenantCount of $totTenants" -status "Please wait" $Company = Get-MsolCompanyInformation -TenantID $tenantItem -ErrorAction SilentlyContinue If (!$?) { $objInvalid = New-Object system.object $objInvalid | Add-Member -Type NoteProperty -Name TenantID -value $tenantItem $myInvalidOutput += $objInvalid } Else { $Company = Get-MsolCompanyInformation -TenantID $tenantItem | Select DisplayName, @{Name='TechnicalNotificationEmails';Expression={[string]::join(";", ($_.TechnicalNotificationEmails))}} $InitialDomain = Get-MsolDomain -TenantID $tenantItem | where {$_.IsInitial -Eq $true} $CompanyAdmins = Get-MsolRoleMember -TenantID $tenantItem -roleobjectID 62e90394-69f5-4237-9190-012177145e10 $objTechNot = New-Object system.object $objTechNot | Add-Member -Type NoteProperty -Name TenantID -value $tenantItem $objTechNot | Add-Member -Type NoteProperty -Name CompanyName -value $Company.DisplayName $objTechNot | Add-Member -Type NoteProperty -Name OnMicrosoftDomain -value $InitialDomain.Name $objTechNot | Add-Member -Type NoteProperty -Name CompanyTechnicalNotificationEmails -value $Company.TechnicalNotificationEmails $myTechNotOutput += $objTechNot foreach($caItem in $CompanyAdmins) { $Email =Get-MsolUser -TenantID $tenantItem -ObjectID $caItem.ObjectID | Select UserPrincipalName, PhoneNumber, MobilePhone, @{Name='AlternateEmailAddresses';Expression={[string]::join(";", ($_.AlternateEmailAddresses))}} $objAdmin = New-Object system.object $objAdmin | Add-Member -Type NoteProperty -Name TenantID -value $tenantItem $objAdmin | Add-Member -Type NoteProperty -Name CompanyName -value $Company.DisplayName $objAdmin | Add-Member -Type NoteProperty -Name OnMicrosoftDomain -value $InitialDomain.Name $objAdmin | Add-Member -Type NoteProperty -Name AdminUserUPN -value $Email.UserPrincipalName $objAdmin | Add-Member -Type NoteProperty -Name AdminUserAltEmail -value $Email.AlternateEmailAddresses $objAdmin | Add-Member -Type NoteProperty -Name AdminUserPhone -value $Email.PhoneNumber $objAdmin | Add-Member -Type NoteProperty -Name AdminUserMobilePhone -value $Email.MobilePhone $myAdminOutput += $objAdmin } } } $myInvalidOutput | export-csv -Path "C:\Scripts\InvalidTenants.csv" -NoTypeInformation $myTechNotOutput | export-csv -Path "C:\Scripts\TechNotList.csv" -NoTypeInformation $myAdminOutput | export-csv -Path "C:\Scripts\CompanyAdminList.csv" -NoTypeInformation
Richard Mueller edited Revision 9. Comment: Modified title casing, added tags
Revision: edited tags
good one.