To run this script, install PowerShell 7 with the PnP PowerShell Module.
First, a tenant app must be created in the Entra admin centre with the following permissions:
SharePointTenantSettings.ReadWrite.All
Sites.ReadWrite.All
User.Read
Sites.FullControl.All
Sites.Manage.All
You will need the client-id and the client-secret to run the script. Replace and in this script with your clientid and clientsecret.
To run this script automatically every day, create a task in the windows task scheduler and link the script.
Thats all, have fun!☕