SOLVED

script shared mailbox with license

Contributor

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

12 Replies
I don't know how to find the license specifically so that it comes out
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.

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")

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 ?
Bonjour,

merci je vais tester cela et vous faire un retour

@oliwer_sundgren @Vasil Michev 

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

 

 

Capture d’écran 2022-11-08 155748.png

 

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

 

 

Capture d’écran 2022-11-08 160128.png

Hello again @Manflo1603 

 

Sorry I misstyped my first reply.
Change the IF statement to this and it should work

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

 

@oliwer_sundgren 

 

hello how are you ?

 

super ça fonctionne nickel par contre j'ai deux autres questions :)

 

comment avez vous trouver le SKU de la licence j'aimerais comprendre pour rechercher cette information la ?

 

et comment puis je le sortir en tableau csv ?

 

merci d'avance

Hello again! @Manflo1603 

Great that it works for you :D 

 

On this site you can find all the licenses and their SKU numbers (Also called GUID in the list) 
Product names and service plan identifiers for licensing - Azure AD - Microsoft Entra | Microsoft Le...

 

And for the second question if you want to export this output to a CSV file you could add a PSCustomObject to structure your output in a table format and then export it to a CSV file. 

I've copied your script below and added some modifications to it so you will get a PsCustomObject and then export that, all you need to to is change the variable called $FilePath to the filepath where you want to store the CSV file 

Connect-ExchangeOnline
Connect-AzureAD
$FilePath = "C:\Users\Oliwer\Folder\Export.csv"
$UPNSharedMailbox = Get-Mailbox -recipientTypeDetails SharedMailbox | Select userprincipalname

$CSVReport = @()

foreach ($UPN in $UPNSharedMailbox)
{
    $SharedMailbox = $UPN.userprincipalname
    $Infouser = Get-AzureADUser -ObjectId $SharedMailbox

    if ($infoUser.AssignedLicenses.Count -gt 0 -And $InfoUser.AssignedLicenses.SkuID -Like "cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46")
    {
        $CSVReport += [pscustomobject][ordered]@{

            User            = $SharedMailbox
            IsLicensed      = "Yes"
        }
    }   
}

$CSVReport | Export-Csv -Path $FilePath -NoTypeInformation

 

 

Let me know if this helps or if you have any other questions :D 

 

Kind Regards
Oliwer Sundgren

 

Bonjour @sundgren,

je vais le tester et voir ce que donne la sortie, merci beaucoup pour votre aide !
j'ai fais quelques modifications et ça ressort super bien merci beaucoup )
best response confirmed by Manflo1603 (Contributor)
Solution

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