5 Start Sharepoint as‐a‐code configuration - dcasota/m365-scripts GitHub Wiki

Configuring Sharepoint using Powershell needs a few modules to install.

To install the new version:

Uninstall-Module -Name SharePointPnPPowerShellOnline -AllVersions -Force
Install-Module -Name PnP.PowerShell
$env:PNPLEGACYMESSAGE='false'

Here a few information about older releases.

Microsoft.Online.SharePoint.PowerShell

install-module -name Microsoft.Online.SharePoint.PowerShell
import-module -name Microsoft.Online.SharePoint.PowerShell

connect-sposervice on an account with MFA doiesn't seem to work. https://github.com/microsoft/Partner-Center-PowerShell/issues/259 https://learn.microsoft.com/en-us/answers/questions/1288552/how-to-fix-the-error-aadsts50076-due-to-a-configur https://learn.microsoft.com/en-us/sharepoint/troubleshoot/administration/connect-sposervice-error?source=recommendations

$creds = Get-Credential
Connect-SPOService -Credential $creds -Url https://tenant-admin.sharepoint.com -ModernAuth $true -AuthenticationUrl https://login.microsoftonline.com/organizations

SharePointPnPPowerShellOnline

Install-Module SharePointPnPPowerShellOnline -Force -Confirm:$False

#Read more: https://www.sharepointdiary.com/2018/03/connect-to-sharepoint-online-using-pnp-powershell.html

#Check if SharePoint Online PnP PowerShell module has been installed
Try {
    Write-host "Checking if SharePoint Online PnP PowerShell Module is Installed..." -f Yellow -NoNewline
    $SharePointPnPPowerShellOnline  = Get-Module -ListAvailable "SharePointPnPPowerShellOnline"
 
    If(!$SharePointPnPPowerShellOnline)
    {
        Write-host "No!" -f Green
 
        #Check if script is executed under elevated permissions - Run as Administrator
        If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
        {  
            Write-Host "Please Run this script in elevated mode (Run as Administrator)! " -NoNewline
            Read-Host "Press any key to continue"
            Exit
        }
 
        Write-host "Installing SharePoint Online PnP PowerShell Module..." -f Yellow -NoNewline
        Install-Module SharePointPnPPowerShellOnline -Force -Confirm:$False
        Write-host "Done!" -f Green
    }
    Else
    {
        Write-host "Yes!" -f Green
        Write-host "Importing SharePoint Online PnP PowerShell Module..." -f Yellow  -NoNewline
        Import-Module SharePointPnPPowerShellOnline -DisableNameChecking
        Write-host "Done!" -f Green
    }
}
Catch{
    write-host "Error: $($_.Exception.Message)" -foregroundcolor red
}

Various

See https://learn.microsoft.com/en-us/training/modules/manage-roles-groups-microsoft-365/10-manage-sharepoint-permissions-prevent-oversharing.