corso/src/cmd/purge/scripts/exchangeRetention.ps1
Georgi Matev 6c989dbd78
Adding new OneDrive and Sharepoint CI cleanup (#2870)
New script for OneDrive and Sharepoint cleanup 

Commit by commit review is encouraged for readability since this involves renames of older scripts.


---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [x] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)


#### Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E

Tested this with `nektos/act `so action logic should be mostly sound. There is one issue with the script installed for exchange that I believe is just a difference the container image used by GHA and the local I could use for `act`
2023-03-20 20:36:27 +00:00

38 lines
1.5 KiB
PowerShell
Executable File

# This is tested on Mac as well as Docker (with m365pnp/powershell image)
# To run in Docker with the script in the current working diredctory
# docker run --rm -it -v "$(pwd):/usr/reset-retnention" -e M365TENANT_ADMIN_USER -e M365TENANT_ADMIN_PASSWORD \
# -w /usr/reset-retnention m365pnp/powershell pwsh -c "./setRetention.ps1"
Param (
[Parameter(Mandatory = $False, HelpMessage = "Exchange Admin email")]
[String]$AdminUser = $ENV:M365_TENANT_ADMIN_USER,
[Parameter(Mandatory = $False, HelpMessage = "Exchange Admin password")]
[String]$AdminPwd = $ENV:M365_TENANT_ADMIN_PASSWORD
)
# Setup ExchangeOnline
if (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) {
$ProgressPreference = 'SilentlyContinue'
Install-Module -Name ExchangeOnlineManagement -MinimumVersion 3.0.0 -Force
$ProgressPreference = 'Continue'
}
Write-Host "`nConnecting to Exchange..."
$password = convertto-securestring -String "$AdminPwd" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AdminUser, $password
Connect-ExchangeOnline -Credential $cred
Write-Host "`nResetting retention..."
# Set retention values for all mailboxes
Get-Mailbox | ForEach-Object {
Write-Host "...for" $_
Set-Mailbox -Identity $_.Alias `
-RetentionHoldEnabled $false `
-LitigationHoldEnabled $false `
-SingleItemRecoveryEnabled $false `
-RetainDeletedItemsFor 0 `
-AuditLogAgeLimit 0 `
-Force
}