ExchangeAdminToolkit.psm1
Function Get-DeletedMailboxList{ <# .Synopsis Gets a list of Deleted mailboxes from exchange and outputs into to a CSV file as well as console .DESCRIPTION Gets a list of Hard deleted mailboxes (Remove-Mailbox, Disable-Mailbox) from all databases in the exchange organisation It then outputs them both to the console and to a CSV file which defaults to c:\temp\DeletedMailboxes.csv .EXAMPLE Get-DeletedMailboxList .EXAMPLE Get-DeletecMailboxList -CSVPath C:\MyDir\File.csv -SupressConsole .LINK http://www.f-e-a-r.co.uk .NOTES Author: Daniel Caulfield - 2017 #> [CmdletBinding(SupportsShouldProcess=$True)] [OutputType([int])] Param ( # Path to CSV File [Parameter(Mandatory=$false, Position=0)] $CSVPath = "$env:TEMP\DeletedMailboxes.csv", # Supress output to the console and just create CSV [switch]$SupressConsole ) Begin{ Write-Verbose "SupressConsole = $SupressConsole, CSVPath = $CSVPath" } Process{ Write-Verbose "Querying all databases for all mailboxes and filtering for deleted" $DeletedMailboxes = Get-mailboxdatabase |Get-MailboxStatistics | Where-Object{$_.DisconnectReason -eq 'Disabled'} | Select-Object DisplayName,TotalItemSize,Database,MailboxGuid,DisconnectDate,DisconnectReason,LastLogonTime,LegacyDN Write-Verbose "Data collected, writing outputs" if ($SupressConsole -eq $False) {Write-Output $DeletedMailboxes} $DeletedMailboxes | ConvertTo-Csv | Out-File $CSVPath } End{ Write-Verbose "Command Complete" } } function Invoke-LoopCheckMoveRequest { <# .Synopsis Starts a loop checking mailbox move request statistics .DESCRIPTION Starts a loop checking mailbox move request statistics for all moves or optionally only ones not completed Use CTRL+C to end the loop .EXAMPLE Start-LoopCheckMoveRequest .EXAMPLE Start-LoopCheckMoveRequest -ExcludeComplete -Interval 120 .LINK http://www.f-e-a-r.co.uk .NOTES Author: Daniel Caulfield - 2017 #> [CmdletBinding()] [OutputType([int])] Param ( # Excludes moves with a ststus of Completed [switch]$ExcludeComplete, #Interval in seconds to run the check [int]$Interval = '60' ) Begin{ Write-Verbose "Starting Loop with an interval of $interval and ExcludeComplete $ExcludeComplete" Write-Output "Starting loop use CTRL+C to stop" $a = '1' } Process{ While ($a = 1){ Write-Verbose 'Running Loop' If ($ExcludeComplete -eq $False) {Get-MoveRequest | Get-MoveRequestStatistics} If ($ExcludeComplete -eq $True) {Get-MoveRequest | Where-Object{$_.status -ne 'Completed'} | Get-MoveRequestStatistics} Write-Output "Next Check $Interval seconds..." Write-Verbose "Going to sleep for $Interval Seconds" Start-Sleep $interval } } } function Invoke-LoopCheckRestoreRequest { <# .Synopsis Starts a loop checking mailbox Request request statistics .DESCRIPTION Starts a loop checking mailbox Restore request statistics for all moves or optionally only ones not completed (default 60 second interval) Use CTRL+C to end the loop .EXAMPLE Start-LoopCheckRestoreRequest .EXAMPLE Start-LoopCheckRestoreRequest -ExcludeComplete -Interval 120 .LINK http://www.f-e-a-r.co.uk .NOTES Author: Daniel Caulfield - 2017 #> [CmdletBinding()] [OutputType([int])] Param ( # Excludes moves with a ststus of Completed [switch]$ExcludeComplete, #Interval in seconds to run the check [int]$Interval = '60' ) Begin{ Write-Verbose "Starting Loop with an interval of $interval and ExcludeComplete $ExcludeComplete" Write-Output "Starting loop use CTRL+C to stop" $a = '1' } process{ While ($a = 1){ Write-Verbose 'Running Loop' If ($ExcludeComplete -eq $False) {Get-MailboxRestoreRequest | Get-MailboxRestoreRequestStatistics} If ($ExcludeComplete -eq $True) {Get-MailboxRestoreRequest | Where-Object{$_.status -ne 'Completed'} | Get-MailboxRestoreRequestStatistics} Write-Output "Next Check $Interval seconds..." Write-Verbose "Going to sleep for $Interval Seconds" Start-Sleep $interval } } } |