Get-MsolSubscription gives me total number of licenses
$Result=""
$Results=@()
$Subscriptions= Get-MsolSubscription | foreach{
$SubscriptionName=$_.SKUPartNumber
$SubscribedOn=$_.DateCreated
$ExpiryDate=$_.NextLifeCycleDate
$Status=$_.Status
$TotalLicenses=$_.TotalLicenses
$Result=@{'Subscription Name'=$SubscriptionName;'Total Licenses'=$TotalLicenses}
$Results+= New-Object PSObject -Property $Result
}
Above code works fine, now i want to combine output of above command with output of Get-MsolAccountSku because that command gives me number of actually used licenses
So i modified code as below:
$Result=""
$Results=@()
$Subscriptions= Get-MsolSubscription | foreach{
$SubscriptionName=$_.SKUPartNumber
$SubscribedOn=$_.DateCreated
$ExpiryDate=$_.NextLifeCycleDate
$Status=$_.Status
$TotalLicenses=$_.TotalLicenses
$consumedLicences = Get-MsolAccountSku | foreach {
$consumed = $_.ConsumedUnits
$name = $_.SkuPartNumber
} | where {$_.name -like $SubscriptionName }
$Result=@{'Subscription Name'=$SubscriptionName;'Total Licenses'=$TotalLicenses;'Used'=$consumed}
$Results+= New-Object PSObject -Property $Result
}
Problem is that for all licences i'm getting same value for used column
Total Licenses Subscription Name Used
-------------- ----------------- ----
48 VISIOCLIENT 9
16 VISIOCLIENT 9
10000 STREAM 9
50 EMSPREMIUM 9
10000 POWERAPPS_INDIVIDUAL_USER 9