PowerShell 7.4 SharePoint Question

Hi everyone,

I’m seeking assistance with constructing a PowerShell script to manage document versions and space on multiple SharePoint sites. My goal is to:

  1. Connect to various SharePoint sites.
  2. Delete older major versioning copies of documents to free up space.
  3. Update version history settings to ensure future document control.
  4. Pull the list of SharePoint sites from a CSV file to handle multiple sites at once.
  5. Produce a log at the end of the script execution.

I’ve encountered challenges with consistent authentication methods, having tried PnP PowerShell and SharePoint REST API. I would appreciate guidance on the best approach for handling credentials and login within this type of script.

How would you approach it out of interest ?

Any advice or examples would be greatly appreciated!

Thank you in advance for your help.

Depends upon where the script will be executing from and if it’s user initiated or fully automated. If you already have workloads in Azure I would opt for an automation account/runbook and use an enterprise app for authn/z

It is for my work organisation, so it will/can be ran from either an elevated user account on a local machine or via a remote desktop we use for dev work. Either way it will be user initiated, and not ran automatically.