Forum Discussion
Export to PST via Powershell
- Aug 10, 2017
No way to do it without going to the SCC and initializing the download via the click-one app, sorry. Perhaps you can automate it via AzCopy or some other tool that takes container/token as input - you can get those via the Result property of Get-ComplianceSearchAction.
As for the cmdlet, make sure you also use the -Format parameter!
The Format parameter specifies the format of the search results when you use the Export switch. Valid values are:
FxStream Export to PST files. This is the only option that's available when you export search results from the Security & Compliance Center.
Mime Export to .eml messsage files. This the default value when you use cmdlets to export the search results.It's most likely what causes the issue in your case.
I have built out a pretty extensive offboarding script that performs a lot of these tasks. I wonder if there is a way to download from multiple exports simultaneously. I am going to be looking into start-job to see if I can maybe start 4 or 5 downloads at once.
Honestly, I think converting to a Shared Mailbox and avoiding PSTs all together is the best idea. However, in the event you can't, the Outlook Interop seems the best alternative for now...
function Add-PSOutlookStore([string]$StoreFilePath) {
[void]($comOutlookNS.AddStore($StoreFilePath))
}
function Remove-PSOutlookStore([string]$StoreFilePath) {
[void]($comOutlookNS.RemoveStore($StoreFilePath))
}
function Export-PSOutlookInbox([string]$EmailAddress, [string]$DestinationFilePath) {
Add-PSOutlookStore($DestinationFilePath)
$comOutlookRcpt = $null
try {
$comOutlookRcpt = $Script:comOutlookNS.CreateRecipient($EmailAddress)
[void]($comOutlookRcpt.Resolve())
}
catch {
Write-PSFMessage -Level Critical -Message "Failed to resolve recipient $EmailAddress"
Write-PSFMessage -Level Verbose -Message $Error[0]
}
if ($comOutlookRcpt) {
for ($i = 0; $i -lt $comOutlookFolderTypes.Length; $i++) {
$comOutlookFolderType = $comOutlookFolderTypes[$i]
Write-PSFMessage -Level VeryVerbose -Message "Iterating through shared folder type $comOutlookFolderType"
try {
$comOutlookRctpFolder = $Script:comOutlookNS.GetSharedDefaultFolder($comOutlookRcpt, $comOutlookFolderType)
if ($comOutlookRctpFolder.DefaultItemType -eq [Microsoft.Office.Interop.Outlook.OlItemType]::olMailItem) {
Write-PSFMessage -Level Host -Message "Successfully copied shared folder"
}
else {
Write-PSFMessage -Level Verbose -Message "Skipping shared folder as it is non-mail"
}
}
catch {
Write-PSFMessage -Level Warning -Message "Failed to get shared folder $comOutlookFolderType"
Write-PSFMessage -Level Verbose -Message $Error[0]
}
}
}
Remove-PSOutlookStore($DestinationFilePath)
}
This is just a partial from my PS module.
- SystemEngineerFeb 06, 2024Iron Contributor
Would you be able to share the link for your PS module?