Jun 08 2019 07:46 AM - edited Jun 08 2019 07:47 AM
Hi,
I'm trying to make a new script in Powershell to display (for a report) the following attributes in a CSV table like this:
DisplayName UserPrincipalName Licenses RecipientTypeDetails TotalItemSize
I need to be displayed the UserMailboxes and SharedMailboxes.
I made separated scripts at first but i've to join all information on a unique file and it's a mess.
Can anyone help me?
Jun 08 2019 11:52 AM
Those are pretty much the most commonly asked for attributes, do a search online and use one of the dozens of already available scripts.
Jun 09 2019 03:01 AM
Jun 09 2019 12:13 PM
Jun 09 2019 11:18 PM
Here you go!
Get-Mailbox -ResultSize Unlimited | Select DisplayName,UserPrincipalName,RecipientTypeDetails,TotalItemSize,@{Name='Licenses';Expression={(Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select -ExpandProperty Licenses).AccountSkuID}} | Export-CSV -NoTypeInformation $env:USERPROFILE\Desktop\File.CSV
Jun 10 2019 02:21 AM - edited Jun 10 2019 06:00 AM
You can try Export Office 365 Mailboxes with Licenses script that will report needed attributes(DisplayName, UPN, Licenses, RecipientTypeDetails). You need to add TotalItemSize alone. To get TotalItemSize, add below line in 110th line of script.
$TotalItemSize=(Get-MailboxStatistics -Identity $upn).TotalItemSize.
Additionally,
Jun 10 2019 04:23 AM
I tried the script but that's the same problem that I had. Exporting that kind of information it only displays the following attributes right:
DisplayName UserPrincipalName RecipientTypeDetails
The other two columns (TotalItemSize and Licenses) are all blank.
To get the TotalItemSize I've to use get-mailboxstatistics am I right?
Jun 10 2019 06:13 AM
That's right... woops, I only tried displayname and licenses and didn't confirm the rest. I'd say do the same thing with TotalItemSize using the format when I retrieve the licenses.
It does help if you can post your actual command 😉
@{Name='Licenses';Expression={(Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select PropertyHere)
Jun 10 2019 06:43 AM
@rootwontfallConfirmed this one has worked... just change the ResultSize to Unlimited
Get-Mailbox -ResultSize 10 | select displayname,UserPrincipalName,RecipientTypeDetails,@{Name='Mailbox Size';Expression={Get-MailboxStatistics $_.UserPrincipalName | Select TotalItemSize}},@{Name='Licenses';Expression={(Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select -ExpandProperty Licenses).AccountSKUID}} |Export-Csv -NoTypeInformation .\Desktop\Test.csv
Jun 11 2019 12:24 AM
The licenses column still blank and I can't understand why.
I got one script (the one I used before) to give me that kind of information just like this:
Get-MsolUser -All |
Select DisplayName,UserPrincipalName,@{n="Licenses";e={$_.Licenses.AccountSKUid}} | Sort-Object DisplayName |
Export-Csv -Path C:\temp\MailboxesLicenciadas.csv -NoTypeInformation
I tried it like this:
Get-Mailbox -ResultSize:Unlimited | select displayname,UserPrincipalName,RecipientTypeDetails,@{Name='Mailbox Size';Expression={Get-MailboxStatistics $_.UserPrincipalName | Select TotalItemSize}},@{Name='Licenses';Expression={Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select -ExpandProperty Licenses.AccountSKUID}} |Export-Csv -NoTypeInformation C:\temp\FullExport.csv
But I can't make it work in your script. Do you've any idea why?
Jun 11 2019 04:48 AM
@rootwontfallYou're missing a parenthesis, order of operations.
(Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select -ExpandProperty Licenses).AccountSKUID
Jun 12 2019 05:49 AM
Even making the following command:
Get-Mailbox -ResultSize:Unlimited | select displayname,UserPrincipalName,RecipientTypeDetails,@{Name='Mailbox Size';Expression={Get-MailboxStatistics $_.UserPrincipalName | Select TotalItemSize}},@{Name='Licenses';Expression={(Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select -ExpandProperty Licenses).AccountSKUID}} |Export-Csv -NoTypeInformation .\Desktop\Test.csv
It still gives me all columns right unless the column called "Licenses".
I've already tried to change the script but the result is the same...
I can't export licenses of each mailboxes.
Thanks for your help @jerome317!
Jun 12 2019 06:58 AM
Jun 12 2019 08:49 AM - edited Jun 12 2019 08:50 AM
Did you use Connect-MsolService to be able to run Get-MsolUser part of the cmd ?
I used the same set of cmdlets and was able to get required data.
Deepak
Jun 12 2019 10:41 AM
@DeepakRandhawa and @jerome317
That's it!
With the complete script I forgot to write at first Connect-MsolServie to get all users licenses.
Thank you so much!
Apr 16 2021 12:19 AM
Mar 28 2022 10:08 PM