powershell for automate exiting user backup

Regular Visitor

Dear All,


I googled for a while but did not find a feasible solution.


I have a working script that disables (i.e sets the expiration date) AD user accounts (hybrid environment).


I would like to automate the fact that after 30 days from the expiration date the system backup the user's email account and onedrive files. 


I see that is possible using the compliance center Powershell module to do something but did not find a full solution to automate the export. 


Do someone have any link to point?


Any help will be really appreciate

1 Reply



From my experience and knowledge you can use the E-Discovery/Content Search powershell module to script this up to the part of the actul export/download of the results from your search. 

This is because the tool to actually download the results from E-Discovery uses a Click-One application together with a token. 


So in other words, you would be able to automate the part where data is searched and secured in an E-discovery case, but the export of the results themselves would have to be done manually via the GUI. 


Some powershell code to get you started. 


$User = "user@domain.com"
$SearchName = "Email Backup - $($User)" 

New-ComplianceSearch -Name $SearchName -ExchangeLocation $User

Start-ComplianceSearch -Name $SearchName

Start-Sleep -s 5
$complianceSearch = Get-ComplianceSearch $SearchName
while ($complianceSearch.Status -ne 'Completed')

New-ComplianceSearchAction -Name $SearchName -Export -ExchangeArchiveFormat PerUserPst


The above PowerShell command creates an E-Discovery/content search case for you in the name format of "Email Backup - User@domain.com" 

Then it starts search for the case, and when the search is completed it starts the export action for that user. 


When the export is done you would then have to actually download the PST file from SCC :) 


Hope this helps, and If I've misunderstood your question feel free to message me or reply here and we can discuss further.


Kind Regards
Oliwer Sundgren