Powershell Script to Export Exchange mailbox to smaller PST Chunks

Powershell Script to Export Exchange mailboxes in 20GB PST allotments for upload to Mimecast [pastacode lang=”markdown” manual=”Import-Module%20activedirectory%0A%0A%24TargetUserName%3D%22jsmith%22%0A%24Useremail%3D%22jsmith%40domain.com%0A%24Location%20%3D%20%22%5C%5C10.1.10.18%5CArchiveExport%5C%22%0A%0A%24FirstEmail%20%3D%20Get-MailboxFolderStatistics%20%24TargetUserName%20-IncludeOldestAndNewestItems%20%7C%20%3F%20%7B%24_.OldestItemReceivedDate%7D%20%7C%20Sort-Object%20OldestItemReceivedDate%20%7C%20Select%20-ExpandProperty%20OldestItemReceivedDate%20-First%201%0A%24FirstEmail%20%3D%20%24FirstEmail.ToString(%22MM%2Fdd%2Fyyyy%22)%0A%0A%24finish%20%3D%20%24FirstEmail%0A%0A%23The%20end%20date%20of%20when%20the%20last%20email%20wants%20to%20be%20exported%20%2C%20if%20using%20Mimecast%20this%20will%20be%20the%20date%20of%20enabling%20archiving%0A%24startdate%20%3D%20Get-Date%0A%0A%24startofmonth%20%3D%20Get-Date%20%24startdate%20-day%201%20-hour%200%20-minute%200%20-second%200%0A%0A%24endofmonth%20%3D%20((%24startofmonth).AddMonths(1).AddSeconds(-1))%0A%0A%24pstnumber%20%3D%201%0A%0Ado%20%7B%0A%24startvalue%20%3D%20Get-Date%20-format%20d%20-Date%20%24startofmonth%0A%0A%24endvalue%20%3D%20Get-Date%20-format%20d%20-Date%20%24endofmonth%0A%0ANew-MailboxExportRequest%20%24TargetUserName%20-ContentFilter%20%22((Received%20-gt%20’%24startofmonth’)%20-and%20(Received%20-lt%20’%24endofmonth’))%22%20-FilePath%20%24Location%24Useremail%22.pst%22%20-Confirm%3A%24false%0A%0A%24ExportStats%20%3D%20Get-MailboxExportRequest%20-Mailbox%20%24TargetUserName%0A%24ExportStatus%20%3D%20%24ExportStats.Status%0A%0ADo%7B%0AStart-Sleep%2010%0A%24ExportStats%20%3D%20Get-MailboxExportRequest%20-Mailbox%20%24TargetUserName%0A%24ExportStatus%20%3D%20%24ExportStats.Status%0A%7D%20while%20(%24ExportStatus%20-eq%20%22Queued%22%20-or%20%24ExportStatus%20-eq%20%22InProgress%22)%0A%0AStart-Sleep%2030%0A%0AGet-MailboxExportRequest%20-mailbox%20%24targetusername%20-Status%20%22Completed%22%20%7C%20Remove-MailboxExportRequest%20-Confirm%3A%24false%0A%0AStart-Sleep%2030%0A%0Aif((Get-Item%20%24Location%24useremail%22.pst%22).length%20-gt%2020gb)%20%7B%0ARename-Item%20%24Location%24Useremail%E2%80%9D.PST%E2%80%9D%20%24Location%24Useremail%E2%80%9D.%E2%80%9C%24pstnumber%E2%80%9D.PST%E2%80%9D%0A%24pstnumber%2B%2B%0A%7D%0A%0A%24startofmonth%20%3D%20((%24startofmonth).AddMonths(-1))%0A%0A%24endofmonth%20%3D%20((%24startofmonth).AddMonths(1).AddSeconds(-1))%0A%0AStart-Sleep%2030%0A%0A%7D%0A%0Awhile%20(%24startofmonth%20-ge%20%24finish)%0A” message=”” highlight=”” provider=”manual”/]

Refresh Azure AD auth token

[pastacode lang=”markdown” manual=”%23%20Revoke%20tokens%20in%20Azure%20AD%2C%20existing%20application%20and%20browser%20windows%20with%20access%20token%20needs%20to%20be%20terminated%20to%20revoke%20the%20access%20token%0A%0AGet-AzureADUser%20-SearchString%20user%40domain.com%20%7C%20Revoke-AzureADUserAllRefreshToken%0A%0ASet-User%20-Identity%20user%40domain.com%20-AuthenticationPolicy%20%22Allow%20Basic%20Auth%20for%20ActiveSync%22%20-StsRefreshTokensValidFrom%20%24(%5BSystem.DateTime%5D%3A%3AUtcNow)%20%0A%0ASet-User%20-Identity%20user%40domain.com%20-AuthenticationPolicy%20%22Disable%20Basic%20Auth%22%20-StsRefreshTokensValidFrom%20%24(%5BSystem.DateTime%5D%3A%3AUtcNow)%20%0A%0A%20″ message=”” highlight=”” provider=”manual”/]