Skip to content

CUMTD/MTDPowerShellScripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MTD-AdminTools

GitHub Release GitHub Actions Workflow Status

PowerShell tools for managing SharePoint Online environments at MTD.

πŸ“¦ About

MTD-AdminTools is a PowerShell module developed by MTD to streamline and automate common administrative tasks.


πŸ“‚ Included Cmdlets

Disable-MtdUser

Parameters

Name Type Required Description
RunAsUser string Yes UPN of the admin running the script.
UserPrincipalName string Yes UPN of the user being offboarded.
ManagerEmail string Yes Email address of the user's manager.
DeleteAccount switch No If set, deletes the user instead of disabling.
HybridUser switch No If set, processes the user as a synced on-premises identity.
WhatIf switch No Performs a dry run without making changes.

Example

Import-Module MTD-AdminTools
Disable-MtdUser -RunAsUser me@mtd.org -UserPrincipalName departed@mtd.org -ManagerEmail manager@mtd.org -HybridUser -WhatIf
Disable-MtdUser -RunAsUser me@mtd.org -UserPrincipalName departed@mtd.org -ManagerEmail manager@mtd.org -DeleteAccount -WhatIf

Get-LargeSharePointFiles

Parameters

Name Type Required Description
SharePointAdminUrl string Yes The URL of the SharePoint Admin Center (e.g., https://<tenant>-admin.sharepoint.com). Required to scan all sites.
SiteUrl string No The URL of a specific site to scan (e.g., https://<tenant>.sharepoint.com/sites/YOURSITE).
SizeThresholdMB int No File size threshold in megabytes (default: 500).

Example

Import-Module MTD-AdminTools
Get-LargeSharePointFiles -SiteUrl "https://<tenant>-admin.sharepoint.com" -SizeThresholdMB 1024
Get-LargeSharePointFiles -SiteUrl "https://<tenant>.sharepoint.com/sites/YOURSITE" -SizeThresholdMB 1024

Get-StaleIntuneDevices

Parameters

Name Type Required Description
DaysInactive int No Number of days since last check-in (default: 90).

Example

Import-Module MTD-AdminTools
Get-StaleIntuneDevices -DaysInactive 120

Remove-OldSharePointVersions

Deletes non-current file versions older than a specified number of days from all document libraries in a SharePoint site.

Parameters

Name Type Required Description
SiteUrl string Yes Full URL of the site to scan.
DaysToKeep int No Versions older than this number of days are deleted (default: 365).

Example

Import-Module MTD-AdminTools
Remove-OldSharePointVersions -SiteUrl "https://<tenant>.sharepoint.com/sites/YOURSITE" -DaysToKeep 180

Remove-StaleIntuneDevices

Example

Import-Module MTD-AdminTools
Get-StaleIntuneDevices -DaysInactive 120 | Remove-StaleIntuneDevices

Set-SharePointRetention

Configures version-history retention on SharePoint Online sites by enabling automatic trimming or applying custom version/age limits.

Parameters

Name Type Required Description
SharePointAdminUrl string Yes URL of the SharePoint Admin Center (e.g., https://contoso-admin.sharepoint.com).
SiteUrl string No Site URL to target (e.g., https://contoso.sharepoint.com/sites/YOURSITE). Defaults to all sites if omitted.
EnableAutoExpirationVersionTrim switch Auto mode Enables automatic version trimming. Mutually exclusive with custom mode.
ExpireVersionsAfterDays int Custom mode Deletes versions older than the specified number of days.
MajorVersionLimit int Custom mode Keeps only the specified number of major versions.
MajorWithMinorVersionsLimit int Custom mode Also retains minor versions for the last N major versions (in addition to MajorVersionLimit).
ApplyToExistingDocumentLibraries switch No Targets existing libraries (default if no apply flag is used).
ApplyToNewDocumentLibraries switch No Also applies settings to libraries created after this change.

Note: In Custom mode, at least one of -ExpireVersionsAfterDays, -MajorVersionLimit, or -MajorWithMinorVersionsLimit is required.

Example

Import-Module MTD-AdminTools

# Automatic version trimming across all sites, including new libraries
Set-SharePointRetention `
  -SharePointAdminUrl "https://contoso-admin.sharepoint.com" `
  -EnableAutoExpirationVersionTrim `
  -ApplyToNewDocumentLibraries

# Custom limits on a specific site: keep max 50 majors & delete versions older than 90 days
Set-SharePointRetention `
  -SharePointAdminUrl "https://contoso-admin.sharepoint.com" `
  -SiteUrl "https://contoso.sharepoint.com/sites/YOURSITE" `
  -MajorVersionLimit 50 `
  -ExpireVersionsAfterDays 90 `
  -ApplyToExistingDocumentLibraries

πŸ“₯ Installation

πŸ”§ Requirements

Before using the module, ensure the following are installed:

πŸ“¦ Option 1: Install via GitHub Release

  1. Go to the Releases page.
  2. Download the latest MTD-AdminTools.zip.
  3. Extract to a folder, e.g. C:\Modules\MTD-AdminTools.
  4. Import:
Import-Module 'C:\Modules\MTD-AdminTools\MTD-AdminTools.psd1'

πŸ’» Option 2: Clone the Repo (for Contributors)

git clone git@github.com:CUMTD/MTDPowerShellScripts.git
cd MTDPowerShellScripts
\$env:PSModulePath += ";\$PWD"
Import-Module "\$PWD/MTD-AdminTools.psd1"

βš™οΈ Option 3: Use the Installer Script

.\scripts\Install-MTDAdminTools.ps1 [-TargetPath "C:\Modules\MTD-AdminTools"]
Import-Module MTD-AdminTools

πŸ§ͺ Verify Installation

Get-Command -Module MTD-AdminTools

You should see commands like:

CommandType     Name                          ModuleName
-----------     ----                          ----------
Function        Get-LargeSharePointFiles     MTD-AdminTools
Function        Set-SharePointRetention       MTD-AdminTools

🧰 Development

Repo Structure

MTDPowerShellScripts/
β”œβ”€β”€ Public/
β”œβ”€β”€ Private/
β”œβ”€β”€ MTD-AdminTools.psm1
β”œβ”€β”€ MTD-AdminTools.psd1
β”œβ”€β”€ scripts/
β”œβ”€β”€ .editorconfig
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .gitattributes
└── .vscode/

πŸ“œ License

Licensed under the Apache License 2.0.

About

PowerShell tools for managing SharePoint Online environments at MTD.

Resources

License

Stars

Watchers

Forks

Packages

No packages published