{"id":9036,"date":"2025-07-08T03:04:08","date_gmt":"2025-07-08T03:04:08","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=9036"},"modified":"2025-07-08T03:04:09","modified_gmt":"2025-07-08T03:04:09","slug":"powershell-to-get-shared-mailbox-with-licenses","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/powershell-to-get-shared-mailbox-with-licenses","title":{"rendered":"Powershell to get shared mailbox with licenses"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code class=\"\"># Ensure TLS 1.2 for secure connections\n[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\n# Check PowerShell version\n$psVersion = $PSVersionTable.PSVersion.Major\nif ($psVersion -ge 7) {\n    Write-Warning \"PowerShell $psVersion may have compatibility issues with ExchangeOnlineManagement. Windows PowerShell 5.1 is recommended.\"\n} else {\n    Write-Host \"PowerShell $psVersion detected. Proceeding.\" -ForegroundColor Green\n}\n\n# Check and install ExchangeOnlineManagement module\n$module = Get-Module -ListAvailable -Name ExchangeOnlineManagement\nif (-not $module) {\n    Write-Host \"Installing ExchangeOnlineManagement module...\" -ForegroundColor Yellow\n    try {\n        Install-Module -Name ExchangeOnlineManagement -Force -Scope CurrentUser -ErrorAction Stop\n        Write-Host \"Module installed successfully.\" -ForegroundColor Green\n    } catch {\n        Write-Host \"Failed to install module. Error: $_\" -ForegroundColor Red\n        exit\n    }\n} else {\n    Write-Host \"ExchangeOnlineManagement module already installed.\" -ForegroundColor Green\n}\n\n# Import module\nImport-Module ExchangeOnlineManagement\n\n# Connect to Exchange Online\ntry {\n    Connect-ExchangeOnline -ShowProgress $true -ErrorAction Stop\n} catch {\n    Write-Host \"Failed to connect to Exchange Online. Error: $_\" -ForegroundColor Red\n    exit\n}\n\n# Get shared mailboxes with licenses\n$results = Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited |\n    ForEach-Object {\n        $user = Get-User -Identity $_.UserPrincipalName -ErrorAction SilentlyContinue\n        if ($user -and $user.IsLicensed) {\n            [PSCustomObject]@{\n                DisplayName        = $_.DisplayName\n                UserPrincipalName  = $_.UserPrincipalName\n                PrimarySmtpAddress = $_.PrimarySmtpAddress\n                LicenseStatus      = \"Licensed\"\n            }\n        }\n    }\n\n# Disconnect from Exchange Online\nDisconnect-ExchangeOnline -Confirm:$false\n\n# Export results to CSV\n$csvPath = \"C:\\Temp\\LicensedSharedMailboxes.csv\"\nif ($results) {\n    $results | Export-Csv -Path $csvPath -NoTypeInformation -Encoding UTF8\n    Write-Host \"Licensed shared mailboxes exported to $csvPath\" -ForegroundColor Green\n} else {\n    Write-Host \"No licensed shared mailboxes found.\" -ForegroundColor Yellow\n}\n\n# Display results\n$results | Format-Table -AutoSize<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9036","post","type-post","status-publish","format-standard","hentry","category-research"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/9036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=9036"}],"version-history":[{"count":1,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/9036\/revisions"}],"predecessor-version":[{"id":9037,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/9036\/revisions\/9037"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=9036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=9036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=9036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}