Forum Discussion
Powershell: get data from MsOnline
- Jul 15, 2022Nice, expanding on my ugly script 😛
mfranhind115 Wrote a post about getting the license state and details for all users a while ago, perhaps a good start to expand on?
#Connect to MSOL if not connected
Write-Host Checking MSOnline module -ForegroundColor Green
try {
Get-MsolDomain -ErrorAction Stop | Out-Null
}
catch {
if (-not (get-module -ListAvailable | Where-Object Name -Match 'MSOnline')) {
Write-Host Installing MSOnline module.. -ForegroundColor Green
Install-Module MSOnline
}
Connect-MsolService
}
#Create table of users and licenses (https://docs.microsoft.com/en-us/azure/active-directory/enterprise-users/licensing-service-plan-reference)
#Download csv with all SKU's
$ProgressPreference = "SilentlyContinue"
Write-Host Downloading license overview from Microsoft -ForegroundColor Green
$csvlink = ((Invoke-WebRequest -Uri https://docs.microsoft.com/en-us/azure/active-directory/enterprise-users/licensing-service-plan-reference).Links | where-Object Href -Match 'CSV').href
Invoke-WebRequest -Uri $csvlink -OutFile $env:TEMP\licensing.csv
$skucsv = Import-Csv -Path $env:TEMP\licensing.csv
$UsersLicenses = @()
foreach ($user in Get-MsolUser -All | Sort-Object UserPrincipalName) {
if ($user.isLicensed -eq $True) {
foreach ($License in $User.licenses) {
$SKUfriendlyname = $skucsv | Where-Object String_Id -Contains $License.AccountSkuId.Split(':')[1] | Select-Object Product_Display_Name -First 1
$SKUserviceplan = $skucsv | Where-Object String_Id -Contains $License.AccountSkuId.Split(':')[1] | Sort-Object Service_Plans_Included_Friendly_Names
foreach ($serviceplan in $SKUserviceplan) {
$Licenses = [PSCustomObject]@{
User = $User.UserPrincipalName
LicenseSKU = $SKUfriendlyname.Product_Display_Name
Serviceplan = $serviceplan.Service_Plans_Included_Friendly_Names
}
$UsersLicenses += $Licenses
}
}
}
}
#Output all license information to c:\temp\userslicenses.csv and open it
$UsersLicenses | Sort-Object User, LicenseSKU, Serviceplan | Export-Csv -NoTypeInformation -Delimiter ';' -Encoding UTF8 -Path c:\temp\userslicenses.csv
Invoke-Item c:\temp\userslicenses.csv
(https://powershellisfun.com/2022/05/16/microsoft-365-license-overview-per-user/)
But could you show us what you already have and how the output of that is?
- mfranhind115Jul 14, 2022Brass Contributor
Hi Harm and many thanks
I would try your suggestion soon and let you know
at the moment I only extract separately the infos and combine them with excel formulas
but, for examples, I get all the licenses and features, so I have to check visually what licenses I'm interested of
then it is a lot time expensive- mfranhind115Jul 14, 2022Brass Contributorjust tried the script
but it seems going stuck requesting for the web
any chance to avoid that request in your opinion?- Jul 14, 2022
? Could you show a screenshot? Did it install the module if not present and did it prompt for Global Admin credentials? (Should show a modern authentication logon screen)