Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinblumenfeld/9106ae16d7384629010c5f1e1421e0e4 to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/9106ae16d7384629010c5f1e1421e0e4 to your computer and use it in GitHub Desktop.
function Get-LAMailboxHold {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[string[]] $list
)
Begin {
$row = @()
$resultArray = @()
$findParameter = "InPlaceHolds"
# $mailbox = Get-Mailbox -IncludeInactiveMailbox -ResultSize 10 | Select DisplayName, accountdisabled, IsInactiveMailbox, RecipientTypeDetails, UserPrincipalName, LitigationHoldEnabled, RetentionPolicy, RecoverableItemsQuota, InPlaceHolds
$mbxSearch = Get-MailboxSearch -ResultSize unlimited | select name, inplaceholdidentity, Status, version, StartDate, EndDate, sourcemailboxes, ItemHoldPeriod
$hash = @{}
foreach ($sRow in $mbxSearch) {
foreach ($id in $sRow.InPlaceHoldIdentity) {
$hash[$id] = $sRow
}
}
}
Process {
if (! $mailboxProperties) {
$mailboxProperties = Get-Mailbox -Identity $_.userprincipalname | Select displayname, userprincipalname, inplaceholds, IsInactiveMailbox, accountdisabled, RecipientTypeDetails| Get-Member -MemberType 'NoteProperty' | Select Name
}
foreach ($mailbox in $list) {
$row = Get-Mailbox -Identity $mailbox
ForEach ($guid in $row.$findParameter) {
$mailboxHash = @{}
$mailboxHash['InPlaceHoldName'] = ($hash[$guid]).name
$mailboxHash['StatusofHold'] = ($hash[$guid]).Status
$mailboxHash['StartDate'] = ($hash[$guid]).StartDate
$mailboxHash['EndDate'] = ($hash[$guid]).EndDate
$mailboxHash['ItemHoldPeriod'] = ($hash[$guid]).ItemHoldPeriod
foreach ($field in $mailboxProperties.name) {
$mailboxHash[$field] = ($row.$field) -join ","
}
$resultArray += [psCustomObject]$mailboxHash
}
}
}
End {
$resultArray
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment