Forum Discussion
rootwontfall
Jun 08, 2019Copper Contributor
Script to export to CSV all Mailboxes and SharedMailboxes
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 ...
jerome317
Brass Contributor
rootwontfallYou're missing a parenthesis, order of operations.
(Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select -ExpandProperty Licenses).AccountSKUID
rootwontfall
Jun 12, 2019Copper Contributor
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!
- jerome317Jun 12, 2019Brass ContributorWeird. Exact script I ran and shows results, License is blank if it is a Shared/Resource mailbox.
So if you run a separate command using this, does it show licenses?
Get-MsolUser -UserPrincipalName YOUR_UPN@contoso.com | select DisplayName,Licenses- DeepakRandhawaJun 12, 2019Iron Contributor
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
- rootwontfallJun 12, 2019Copper Contributor
That's it!
With the complete script I forgot to write at first Connect-MsolServie to get all users licenses.
Thank you so much!