Mk_msoffice.ps1 not working anymore

Hello there!

Since Microsoft is deprecating the MSOnline PowerShell module and their endpoints this month (for us it currently isn’t working as communicated by Microsoft) I went ahead and wrote a replacement script. Instead of requiring an Entra user and using username and password I created an application and connect via client secrets. The application will need the “Organization.Read.All” Graph application scope, you will have to have installed the Microsoft.Graph PowerShell module where you use this script.

Then just use this script, enter the three values for the secret, application id and tenant id:

$Secret = "xxx"
$AppId = "xxx"
$TenantId = "xxx"

$SecureClientSecret = ConvertTo-SecureString -String $Secret -AsPlainText -Force
$ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AppId, $SecureClientSecret

Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $ClientSecretCredential -NoWelcome
$licenses = Get-MgSubscribedSKU -All

write-host "<<<msoffice_licenses>>>"
foreach ($license in $licenses) {
    $line = "{0}:{1} {2} {3} {4}" -f $license.AccountName, $license.SkuPartNumber, $license.PrepaidUnits.Enabled, $license.PrepaidUnits.Warning, $license.ConsumedUnits
    write-host $line
}

write-host "<<<msoffice_serviceplans>>>"
foreach ($license in $licenses) {
    foreach ($serviceplan in $license.ServicePlans) {
        $line = "{0}:{1} {2} {3}" -f $license.AccountName, $license.SkuPartNumber, $serviceplan.ServicePlanName, $serviceplan.ProvisioningStatus
        write-host $line
    }
}

Maybe it is helpful for someone else, there is already a ticket open about the future of these checks. Maybe in the future this won’t be a script running on a windows client, maybe a special agent can do this directly via REST. Also having the ability to get this info for multiple tenants would be great, right now I just copy my script to get a 2nd tenants license info.

1 Like

Thanks. We will migrate the plug-in to MS Graph as well soon.