forked from realmjoin/customer-runbooks-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-properties-of-a-single-mailbox.ps1
56 lines (44 loc) · 2.21 KB
/
get-properties-of-a-single-mailbox.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<#
.SYNOPSIS
Get a list of all shared mailboxes and their attributes.
.DESCRIPTION
Fetches all existing shared mailboxes and their respective attributes as JSON.
#>
#Requires -Modules @{ModuleName = "RealmJoin.RunbookHelper"; ModuleVersion = "0.8.3" }, ExchangeOnlineManagement
param (
[Parameter(Mandatory = $true)]
[string] $MailboxUPN,
## CallerName is tracked purely for auditing purposes
[Parameter(Mandatory = $true)]
[TypeName] $CallerName
)
Write-RjRbLog -Message "Caller: '$CallerName'" -Verbose
try {
Connect-RjRbExchangeOnline
Write-Host "## Grabbing information for the provided mailbox..."
$mailboxData = Get-EXOMailbox -Identity $MailboxUPN -Properties DisplayName, UserPrincipalName, EmailAddresses, RecipientTypeDetails, PrimarySmtpAddress, ExchangeObjectId, WhenCreated, IsMailboxEnabled, DistinguishedName, OrganizationalUnit, ExchangeVersion
$orgUnitRoot = Get-Mailbox -Identity $MailboxUPN | Select-Object OrganizationalUnitRoot
if($null -eq $mailboxData || $null -eq $orgUnitRoot){
throw "## Mailbox does not exist. Check spelling and try again."
}
$mailboxAttributes = New-Object -TypeName PSObject -Property @{
ExchangeObjectId = $mailboxData.ExchangeObjectId
WhenCreated = $mailboxData.WhenCreated
IsMailboxEnabled = $mailboxData.IsMailboxEnabled
OrganizationalUnitRoot = $orgUnitRoot.OrganizationalUnitRoot
OrganizationalUnit = $mailboxData.OrganizationalUnit
DisplayName = $mailboxData.DisplayName
UserPrincipalName = $mailboxData.UserPrincipalName
EmailAddresses = $mailboxData.EmailAddresses
RecipientTypeDetails = $mailboxData.RecipientTypeDetails
PrimarySmtpAddress = $mailboxData.PrimarySmtpAddress
DistinguishedName = $mailboxData.DistinguishedName
ExchangeVersion = $mailboxData.ExchangeVersion
}
Write-Host "## Saving all data to a .json file..."
$mailboxAttributes | ConvertTo-JSON | Out-File -FilePath ".\$($MailboxUPN)_Attributes.json"
Write-Host "## File saved under '$($MailboxUPN)_Attributes.json'. "
}
finally {
Disconnect-ExchangeOnline -Confirm:$false -ErrorAction Continue | Out-Null
}