Office 365-Script for getting license info from Microsoft Partner Center

Posted: June 1, 2018 in Scripts

Set Native App ID  (see section Native applications) in Microsoft partner center.

From Microsoft Partner Center you can manage your customers, offers, subscriptions, usage, etc.

Install Partner center Powershell module

Install-Module -Name PartnerCenterModule

If you’ll run this report at regular basis encrypt credentials:

#partner center credentials

$password = "somepass"
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
$secureStringText = $secureStringPwd | ConvertFrom-SecureString
Set-Content "C:\temp\ExportedPassword.txt" $secureStringText

 

#email (office365) credentials

$password = "somepass"
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
$secureStringText = $secureStringPwd | ConvertFrom-SecureString
Set-Content "C:\temp\mail.txt" $secureStringText

Following code will get license usage

#Partner center credentials

$username = "partnercenteradmin@mojdomen.com"
$pwdTxt = Get-Content "C:\temp\ExportedPassword.txt"
$securePwd = $pwdTxt | ConvertTo-SecureString

 

#email credentials

$mailuser = "korisnik@mojdomen.com"
$pwdmail = Get-Content "C:\temp\mail.txt"
$securemailPwd = $pwdmail | ConvertTo-SecureString

 

# Variables
$cspdomain = "mojdomen.com"
$appid = "1223-scdd-ddadadad-11221211"
$PCcreds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd
$EmailCreds = New-Object System.Management.Automation.PSCredential -ArgumentList $mailuser, $securemailPwd
$From = "korisnik@mojdomen.com"
$To = "korisnk@mojdomen.com"
$SmtpServer = "smtp.office365.com"
$Subject = "Partner Center Licensing: "

# Build email parameters
$EmailParameters = @{
from = $From
To = $To
SmtpServer = $SmtpServer
Port = 587
UseSsl = $true
BodyAsHtml = $true
Credential = $EmailCreds
}

# Authentication
Add-PCAuthentication -cspAppID $appid -credential $PCcreds -cspdomain $cspdomain

# Get customers
$Customers = Get-PCCustomer -all

# For each customer
foreach ($Customer in $Customers) {
$CustomerReport = Get-PCCustomerLicensesDeployment -tenantid $Customer.id 2> Out-Null

# If there is a customer licence report
if ($CustomerReport){

# Return specific headings
$CustomerReport = $CustomerReport | Select-Object productName,licensesDeployed,deploymentPercent,licensesSold

# Create customer specific variable
$CustomerSubject = $Subject+$Customer.companyprofile.companyName

# Create Body HTML string
$CustomerBody = $CustomerReport | ConvertTo-Html | Out-String

# Send message
Send-Mailmessage `
-Subject $CustomerSubject `
-Body $CustomerBody `
@EmailParameters
}
}

 

If we have multiple customers, for each of them email will be generated

 

1

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s