Script to export to CSV all Mailboxes and SharedMailboxes

%3CLINGO-SUB%20id%3D%22lingo-sub-678988%22%20slang%3D%22en-US%22%3EScript%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-678988%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20make%20a%20new%20script%20in%20Powershell%20to%20display%20(for%20a%20report)%20the%20following%20attributes%20in%20a%20CSV%20table%20like%20this%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3EDisplayName%26nbsp%3B%20%26nbsp%3BUserPrincipalName%26nbsp%3B%20%26nbsp%3BLicenses%26nbsp%3B%20%26nbsp%3BRecipientTypeDetails%26nbsp%3B%20%26nbsp%3BTotalItemSize%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20be%20displayed%20the%20UserMailboxes%20and%20SharedMailboxes.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20made%20separated%20scripts%20at%20first%20but%20i've%20to%20join%20all%20information%20on%20a%20unique%20file%20and%20it's%20a%20mess.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20help%20me%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-678988%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-679116%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-679116%22%20slang%3D%22en-US%22%3E%3CP%3EThose%20are%20pretty%20much%20the%20most%20commonly%20asked%20for%20attributes%2C%20do%20a%20search%20online%20and%20use%20one%20of%20the%20dozens%20of%20already%20available%20scripts.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-679429%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-679429%22%20slang%3D%22en-US%22%3EHi%20%3CBR%20%2F%3E%3CBR%20%2F%3EAs%20Vasil%20mentioned%20there%20is%20plenty%20of%20scripts%20out%20there%20to%20assist%20with%20this%20issue.%20This%20issue%20is%20also%20a%20great%20step%20stone%20for%20building%20your%20own%20solid%20powershell%20scripts.%20%3CBR%20%2F%3E%3CBR%20%2F%3ESharing%20your%20current%20code%20would%20help%20people%20like%20myself%20and%20Vasil%20guide%20on%20how%20to%20get%20your%20script%20into%20the%20place%20you%20would%20like%20it%20to%20be.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20also%20suggest%20looking%20at%20PowerShell%20ISE%20Steriods%2C%20it's%20a%20minor%20cost%20but%20helps%20massively%20improve%20your%20scripting.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-679663%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-679663%22%20slang%3D%22en-US%22%3Elots%20of%20good%20resources%20for%20learning%20how%20to%20do%20this%20are%20at%20%3CA%20href%3D%22https%3A%2F%2Fabsolute-sharepoint.com%2F2018%2F03%2Fresources-to-learn-powershell-for-office-365.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fabsolute-sharepoint.com%2F2018%2F03%2Fresources-to-learn-powershell-for-office-365.html%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-679986%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-679986%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F356950%22%20target%3D%22_blank%22%3E%40rootwontfall%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20you%20go!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EGet-Mailbox%20-ResultSize%20Unlimited%20%7C%20Select%20DisplayName%2CUserPrincipalName%2CRecipientTypeDetails%2CTotalItemSize%2C%40%7BName%3D'Licenses'%3BExpression%3D%7B(Get-MsolUser%20-UserPrincipalName%20%24_.UserPrincipalName%20%7C%20Select%20-ExpandProperty%20Licenses).AccountSkuID%7D%7D%20%7C%20Export-CSV%20-NoTypeInformation%20%24env%3AUSERPROFILE%5CDesktop%5CFile.CSV%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-680237%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-680237%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F328428%22%20target%3D%22_blank%22%3E%40jerome317%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20the%20script%20but%20that's%20the%20same%20problem%20that%20I%20had.%20Exporting%20that%20kind%20of%20information%20it%20only%20displays%20the%20following%20attributes%20right%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EDisplayName%26nbsp%3B%20%26nbsp%3BUserPrincipalName%26nbsp%3B%20%26nbsp%3BRecipientTypeDetails%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20other%20two%20columns%3CSTRONG%3E%20(TotalItemSize%20and%20Licenses)%20%3C%2FSTRONG%3Eare%20all%20blank.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20get%20the%20TotalItemSize%20I've%20to%20use%20get-mailboxstatistics%20am%20I%20right%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-680142%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-680142%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F356950%22%20target%3D%22_blank%22%3E%40rootwontfall%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BYou%20can%20try%20%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fo365reports.com%2F2019%2F03%2F07%2Fexport-office-365-users-last-logon-time-csv%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EExport%20Office%20365%20Mailboxes%20with%20Licenses%3C%2FA%3E%3C%2FSTRONG%3E%20script%20that%20will%20report%20needed%20attributes(DisplayName%2C%20UPN%2C%20Licenses%2C%20RecipientTypeDetails).%20You%20need%20to%20add%20TotalItemSize%20alone.%20To%20get%20TotalItemSize%2C%20add%20below%20line%20in%20110th%20line%20of%20script.%3C%2FP%3E%3CP%3E%24TotalItemSize%3D(Get-MailboxStatistics%20-Identity%20%24upn).TotalItemSize.%3C%2FP%3E%3CP%3EAdditionally%2C%3C%2FP%3E%3CUL%3E%3CLI%3EThis%20script%20shows%20'Friendly%20Name%20of%20Licenses.%20For%20eg%2C%3CSPAN%3E%26nbsp%3B%E2%80%98Office%20365%20Enterprise%20E3%E2%80%99%20rather%20than%20%E2%80%98ENTERPRISEPACK%E2%80%99.%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3EResult%20can%20be%20filtered%20based%20on%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Euser%20%2F%20all%20mailbox%20type.%3C%2FLI%3E%3CLI%3EThe%20script%20can%20be%20executed%20with%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EMFA%20enabled%20account.%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-680399%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-680399%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F356950%22%20target%3D%22_blank%22%3E%40rootwontfall%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat's%20right...%20woops%2C%20I%20only%20tried%20displayname%20and%20licenses%20and%20didn't%20confirm%20the%20rest.%20I'd%20say%20do%20the%20same%20thing%20with%20%3CSTRONG%3ETotalItemSize%20%3C%2FSTRONG%3Eusing%20the%20format%20when%20I%20retrieve%20the%20licenses.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20does%20help%20if%20you%20can%20post%20your%20actual%20command%20%3B)%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%40%7BName%3D'Licenses'%3BExpression%3D%7B(Get-MsolUser%20-UserPrincipalName%20%24_.UserPrincipalName%20%7C%20Select%20PropertyHere)%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-680484%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-680484%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F356950%22%20target%3D%22_blank%22%3E%40rootwontfall%3C%2FA%3EConfirmed%20this%20one%20has%20worked...%20just%20change%20the%20ResultSize%20to%20Unlimited%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EGet-Mailbox%20-ResultSize%2010%20%7C%20select%20displayname%2CUserPrincipalName%2CRecipientTypeDetails%2C%40%7BName%3D'Mailbox%20Size'%3BExpression%3D%7BGet-MailboxStatistics%20%24_.UserPrincipalName%20%7C%20Select%20TotalItemSize%7D%7D%2C%40%7BName%3D'Licenses'%3BExpression%3D%7B(Get-MsolUser%20-UserPrincipalName%20%24_.UserPrincipalName%20%7C%20Select%20-ExpandProperty%20Licenses).AccountSKUID%7D%7D%20%7CExport-Csv%20-NoTypeInformation%20.%5CDesktop%5CTest.csv%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-682419%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-682419%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F328428%22%20target%3D%22_blank%22%3E%40jerome317%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20%3CSTRONG%3Elicenses%3C%2FSTRONG%3E%20column%20still%20blank%20and%20I%20can't%20understand%20why.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20got%20one%20script%20(the%20one%20I%20used%20before)%20to%20give%20me%20that%20kind%20of%20information%20just%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-MsolUser%20-All%20%7C%3CBR%20%2F%3ESelect%20DisplayName%2CUserPrincipalName%2C%40%7Bn%3D%22Licenses%22%3Be%3D%7B%24_.Licenses.AccountSKUid%7D%7D%20%7C%20Sort-Object%20DisplayName%20%7C%3CBR%20%2F%3EExport-Csv%20-Path%20C%3A%5Ctemp%5CMailboxesLicenciadas.csv%20-NoTypeInformation%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20it%20like%20this%3A%3C%2FP%3E%3CP%3EGet-Mailbox%20-ResultSize%3AUnlimited%20%7C%20select%20displayname%2CUserPrincipalName%2CRecipientTypeDetails%2C%40%7BName%3D'Mailbox%20Size'%3BExpression%3D%7BGet-MailboxStatistics%20%24_.UserPrincipalName%20%7C%20Select%20TotalItemSize%7D%7D%2C%40%7BName%3D'Licenses'%3BExpression%3D%7BGet-MsolUser%20-UserPrincipalName%20%24_.UserPrincipalName%20%7C%20Select%20-ExpandProperty%20Licenses.AccountSKUID%7D%7D%20%7CExport-Csv%20-NoTypeInformation%20C%3A%5Ctemp%5CFullExport.csv%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20can't%20make%20it%20work%20in%20your%20script.%20Do%20you've%20any%20idea%20why%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-683028%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-683028%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F356950%22%20target%3D%22_blank%22%3E%40rootwontfall%3C%2FA%3EYou're%20missing%20a%20parenthesis%2C%20order%20of%20operations.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E(%3C%2FSTRONG%3EGet-MsolUser%20-UserPrincipalName%20%24_.UserPrincipalName%20%7C%20Select%20-ExpandProperty%20Licenses%3CSTRONG%3E)%3C%2FSTRONG%3E.AccountSKUID%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-686940%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-686940%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F328428%22%20target%3D%22_blank%22%3E%40jerome317%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEven%20making%20the%20following%20command%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EGet-Mailbox%20-ResultSize%3AUnlimited%20%7C%20select%20displayname%2CUserPrincipalName%2CRecipientTypeDetails%2C%40%7BName%3D'Mailbox%20Size'%3BExpression%3D%7BGet-MailboxStatistics%20%24_.UserPrincipalName%20%7C%20Select%20TotalItemSize%7D%7D%2C%40%7BName%3D'Licenses'%3BExpression%3D%7B(Get-MsolUser%20-UserPrincipalName%20%24_.UserPrincipalName%20%7C%20Select%20-ExpandProperty%20Licenses).AccountSKUID%7D%7D%20%7CExport-Csv%20-NoTypeInformation%20.%5CDesktop%5CTest.csv%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20still%20gives%20me%20all%20columns%20right%20unless%20the%20column%20called%20%3CSTRONG%3E%22Licenses%22%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20already%20tried%20to%20change%20the%20script%20but%20the%20result%20is%20the%20same...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can't%20export%20licenses%20of%20each%20mailboxes.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20help%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F328428%22%20target%3D%22_blank%22%3E%40jerome317%3C%2FA%3E!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-687146%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-687146%22%20slang%3D%22en-US%22%3EWeird.%20Exact%20script%20I%20ran%20and%20shows%20results%2C%20License%20is%20blank%20if%20it%20is%20a%20Shared%2FResource%20mailbox.%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20if%20you%20run%20a%20separate%20command%20using%20this%2C%20does%20it%20show%20licenses%3F%3CBR%20%2F%3E%3CBR%20%2F%3EGet-MsolUser%20-UserPrincipalName%20YOUR_UPN%40contoso.com%20%7C%20select%20DisplayName%2CLicenses%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-687527%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-687527%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F356950%22%20target%3D%22_blank%22%3E%40rootwontfall%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDid%20you%20use%20Connect-MsolService%20to%20be%20able%20to%20run%20Get-MsolUser%20part%20of%20the%20cmd%20%3F%3C%2FP%3E%3CP%3EI%20used%20the%20same%20set%20of%20cmdlets%20and%20was%20able%20to%20get%20required%20data.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDeepak%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-687996%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20export%20to%20CSV%20all%20Mailboxes%20and%20SharedMailboxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-687996%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F333418%22%20target%3D%22_blank%22%3E%40DeepakRandhawa%3C%2FA%3E%26nbsp%3Band%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F328428%22%20target%3D%22_blank%22%3E%40jerome317%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat's%20it!%3C%2FP%3E%3CP%3EWith%20the%20complete%20script%20I%20forgot%20to%20write%20at%20first%20Connect-MsolServie%20to%20get%20all%20users%20licenses.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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?

14 Replies
Highlighted

Those are pretty much the most commonly asked for attributes, do a search online and use one of the dozens of already available scripts.

Highlighted
Hi

As Vasil mentioned there is plenty of scripts out there to assist with this issue. This issue is also a great step stone for building your own solid powershell scripts.

Sharing your current code would help people like myself and Vasil guide on how to get your script into the place you would like it to be.

I also suggest looking at PowerShell ISE Steriods, it's a minor cost but helps massively improve your scripting.
Highlighted
Highlighted

@rootwontfall 

 

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

 

Highlighted

@rootwontfall 

 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,

  • This script shows 'Friendly Name of Licenses. For eg, ‘Office 365 Enterprise E3’ rather than ‘ENTERPRISEPACK’.
  • Result can be filtered based on user / all mailbox type.
  • The script can be executed with MFA enabled account.

 

 

Highlighted

@jerome317 

 

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?

Highlighted

@rootwontfall 

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)

 

Highlighted

@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

 

Highlighted

@jerome317 

 

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?

Highlighted

@rootwontfallYou're missing a parenthesis, order of operations.

 

(Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select -ExpandProperty Licenses).AccountSKUID

Highlighted

@jerome317 

 

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!

Highlighted
Weird. 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
Highlighted

@rootwontfall 

 

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

Highlighted

@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!