Nov 04 2022 07:43 AM - edited Nov 04 2022 07:44 AM
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
Nov 04 2022 07:46 AM
Nov 04 2022 10:34 AM
Nov 06 2022 04:46 AM - edited Nov 06 2022 04:47 AM
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")
Nov 08 2022 02:01 AM
Nov 08 2022 02:02 AM
Nov 08 2022 07:02 AM
@oliwer_sundgren @Vasil Michev
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
Nov 08 2022 12:58 PM
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")
Nov 09 2022 03:05 AM
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
Nov 13 2022 11:23 AM - edited Nov 13 2022 11:25 AM
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
Nov 15 2022 02:03 AM
Nov 15 2022 04:42 AM
Nov 20 2022 04:00 AM
SolutionNo 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
Nov 20 2022 04:00 AM
SolutionNo 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