Powershell mailboxexportrequest creation and management.

To minimise impact on the server do mailboxexportrequests one at a time and move the completed PST files to a final location as each one is created.

# csv containing alias for each mailbox
$a = import-csv exports.csv

foreach ( $u in $a ) {
			echo "Export $u"
			$ua=$u.alias
			new-mailboxexportrequest $ua -filepath \\pesrv01\exportedemail\$ua.pst
                        #Now wait for it to complete
			do { 
			        sleep 30
                                get-mailboxexportrequest
				$s = Get-MailboxExportRequest -status "completed" | select status
				$s
			}
			until ( $s -ne $null )
			Get-MailboxExportRequest -status "completed" | remove-mailboxexportrequest -confirm:$false
			move  .\$ua.pst '\\OTHERLOCATION\SHARED'
			echo "do next one"
}


About Jeff Turner

Technical director of Nano Tera Network Solutions.
This entry was posted in Powershell, VBS, VBA and other scripting., System Administration. Bookmark the permalink.