Forum Discussion

Manflo1603's avatar
Manflo1603
Brass Contributor
Nov 04, 2022

script shared mailbox with license

I am contacting you because I need your help on a script

I would like to be able to use a script to make it easier for me to export users who have a shared mailbox with a specific license (I would like only those with Business Premium licenses to resort)

 

here is the script

 

< $UPNSharedMailbox = Get-Mailbox -RecipientTypeDetails SharedMailbox | Select-Object userprincipalname

foreach ($UPN in $UPNSharedMailbox)
{
$sharedMailbox = $UPN.UserPrincipalName
$infoUser = Get-AzureAdUser -ObjectId $sharedMailbox

if (!($infoUser.AssignedLicenses.Count -eq 0))
{
echo "$sharedMailbox a used license"
}
} >

 

currently, it takes any type of license

  • No problem at all! Manflo1603 

     

    Feel free to mark my response and an accepted solution if you feel that I helped out in solving your issues 🙂 

     

    If there is anything else I can help with just let me know! Have a great weekend

     

    Kind regards
    Oliwer

  • You could modify the IF Statement by adding an "-And" switch i that looks for a specific SKU of the license that you want to look for. And also by removing the "!" 
    So with the SKU Value that Vasil posted you could change the IF statement to something like this

    if ($infoUser.AssignedLicenses.Count -gt 0 -And $InfoUser.AssignedPlans.ServicePlanID -eq "cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46")

    • Manflo1603's avatar
      Manflo1603
      Brass Contributor
      Bonjour,

      merci je vais tester cela et vous faire un retour
      • Manflo1603's avatar
        Manflo1603
        Brass Contributor

        oliwer_sundgren VasilMichev 

         Rebonjour, quand je fais le script je n'ai pas de rĂ©ponse sortie 

         

         

         

        Par contre si je lance le miens j'ai bien une sortie de rĂ©ponse 

         

         

  • Manflo1603's avatar
    Manflo1603
    Brass Contributor
    I don't know how to find the license specifically so that it comes out
    • VasilMichev's avatar
      VasilMichev
      MVP
      You can filter the AssignedLicenses property based on the SKU value, in the case of M365 Business Premium this will be cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46.
      • Manflo1603's avatar
        Manflo1603
        Brass Contributor
        Merci du retour !

        désole je n'ai pas eu de notification, bref pour mieux comprendre comment avez vous trouvé la valeur sku de la licence ?

Resources