Hi all/ I need to understand whether a MS 365 is assigned directly or via a group, as we are moving to group assigned licenses and I need to run the check to ensure that all of our users are assigned via group not directly.
Welcome to the forums first of all. Second, when you post code, please make sure that it adheres to the coding practices outlined here:
I’ve assisted in the fixed code below as it looks like there appeared to be some missing code. Please confirm the code is correct to your needs. Otherwise, please provide a fixed sample.
#the license SKU we are interested in. use Get-MsolAccountSku to see a list of all identifiers in your organization
$skuId = “contoso:EMS”
#find all users that have the SKU license assigned
Get-MsolUser -All | Where-Object { ($_.isLicensed -eq $true) -and ($_.Licenses.AccountSKUID -eq $skuId) } | `
Select-Object ObjectId,@{Name = “SkuId”; Expression = { $skuId } }, @{Name = "AssignedDirectly"; Expression = { (UserHasLicenseAssignedDirectly $_ $skuId) } }, `
@{Name = “AssignedFromGroup”; Expression = { (UserHasLicenseAssignedFromGroup $_ $skuId) } }
Thanks for the pointers, and there is some missing code. The correct code is as follows:
Hopefully this clarifies.
Thanks
Connect-MsolService
#the license SKU we are interested in. use Get-MsolAccountSku to see a list of all identifiers in your organization
$skuId = "contoso:EMS"
#find all users that have the SKU license assigned
Get-MsolUser -All | where {$_.isLicensed -eq $true -and $_.Licenses.AccountSKUID -eq $skuId} | select `
ObjectId, `
@{Name="SkuId";Expression={$skuId}}, `
@{Name="AssignedDirectly";Expression={(UserHasLicenseAssignedDirectly $_ $skuId)}}, `
@{Name="AssignedFromGroup";Expression={(UserHasLicenseAssignedFromGroup $_ $skuId)}}```
If it were me I would take some time to look into switching your code to the Graph API. Here is a lean doc that may help. I will also try to work on some code later this evening. But specifically I suggest you look at Get-MgUserLicenseDetail