ADScripts/Export-PST.ps1

92 lines
2.3 KiB
PowerShell
Raw Normal View History

2023-09-14 11:13:58 -06:00
## Connect to the Various MS365 Platforms
2023-11-03 14:19:16 -06:00
[CmdletBinding()]
param (
# Define the email address to be exported
[Parameter(Mandatory = $true)]
[string]
$ExportEmail,
# Set this flag if the mailbox is shared
[Parameter(Mandatory = $false)]
[switch]
$SharedMB
)
2023-11-03 14:45:26 -06:00
$dots = "."
$dots2 = "."
2023-09-14 11:13:58 -06:00
Import-Module ExchangeOnlineManagement
2023-11-03 14:45:26 -06:00
if (!$Session) {
$Session = Connect-IPPSSession
}
2023-09-14 11:13:58 -06:00
2023-11-03 14:19:16 -06:00
$user = get-aduser -Filter { mail -eq $ExportEmail }
2023-09-14 11:13:58 -06:00
2023-11-03 14:19:16 -06:00
if ($user) {
2023-11-03 14:45:26 -06:00
$ExportName = $user.Name
2023-11-03 14:19:16 -06:00
}
else {
2023-11-03 14:45:26 -06:00
$ExportName = $ExportEmail
2023-11-03 14:19:16 -06:00
}
2023-09-14 11:13:58 -06:00
## Script Variables
2023-11-03 14:19:16 -06:00
if ($SharedMB) {
# add leading dot if shared mailbox
$ExportEmail = ".$ExportEmail"
}
2023-09-14 11:13:58 -06:00
New-ComplianceSearch $ExportName -ExchangeLocation $ExportEmail -AllowNotFoundExchangeLocationsEnabled $true | Start-ComplianceSearch
2023-11-03 14:19:16 -06:00
2023-09-14 11:13:58 -06:00
do {
$Status = Get-ComplianceSearch -Identity $ExportName
2023-11-03 14:45:26 -06:00
$dots += "."
$Progress = @{
ID = 1
Activity = "Running Search"
Status = $dots
2023-11-03 14:19:16 -06:00
}
Write-Progress @Progress
2023-09-14 11:13:58 -06:00
Start-Sleep -Seconds 10
} while ($Status.status -ne 'Completed')
2023-11-03 14:45:26 -06:00
$Progress = @{
ID = 1
2023-11-03 14:19:16 -06:00
Activity = "Starting Export..."
}
Write-Progress @Progress
2023-09-14 11:13:58 -06:00
2023-11-03 14:45:26 -06:00
$Export_Action_name = New-ComplianceSearchAction $ExportName -Export -format FxStream -Force
# $Export_Action_name.name
2023-09-14 11:13:58 -06:00
do {
$Export_Action = Get-ComplianceSearchAction -Identity $Export_Action_name.Name -IncludeCredential
2023-11-03 14:45:26 -06:00
$dots2 += "."
$Progress = @{
ID = 1
Activity = "Running Export " + $Export_Action_name.Name
Status = $dots2
2023-11-03 14:19:16 -06:00
}
Write-Progress @Progress
2023-09-14 11:13:58 -06:00
Start-Sleep -Seconds 10
} until ($Export_Action.status -eq 'Completed')
2023-11-03 14:45:26 -06:00
Write-Progress @Progress -Completed
2023-09-14 11:13:58 -06:00
#Need to extract Container URI and SAS token from Results, and pass those to AZCopy EXE
#$ContainerURI = $export_action.results.split(';')[0].replace('Container url:','').replace(' ','')
2023-11-03 14:19:16 -06:00
# $SASToken = $export_action.results.split(';')[2].replace(' SAS token: ','')
2023-09-14 11:13:58 -06:00
Write-Output 'Process Complete: Use the SAS Token Below in the "Export" Tab of the following URL: https://compliance.microsoft.com/contentsearch'
2023-11-03 14:19:16 -06:00
# Write-Output 'SAS Token: '
# Write-Output $SASToken
2023-09-14 11:13:58 -06:00
#$FullURI = $ContainerURI + $SASToken
#$AZArgs = " cp '$FullURI' --recursive '$DestinationPath'"
#Start-Process $AZCopyPath $AZArgs
#>
Disconnect-ExchangeOnline