Get All Site Administrators and Owners With Full Control – SharePoint Online PowerShell

A commonly posed question within an organisation that use SharePoint Online is "Can I get a list of all the site administrators?". A perfectly reasonable question, I am sure you will agree. Regardless of whether your role is a SharePoint Administrator, Office 365 Administrator or even a PowerShell Developer, you will spot there is more to this request than meets the eye. You will no doubt start googling looking for scripts that get all SharePoint Administrators or all SharePoint Site Owners. Why re-invent the wheel after all.

Google SharePoint Administrators PowerShell

I found several scripts and blog posts that mostly met my needs. I did feel the need to start from the ground up so this is what I am sharing with you in this post.

Site Administrators or Members with Full Control?

Most administrators will find themselves looking initially at Get-PnPSiteCollectionAdmin, which is an admirable starting point.

Read More

Adding Retention Labels to Subfolders in SharePoint Online and OneDrive

Having authenticated to a SharePoint online Site, Site Collection or a OneDrive site, like me, you may have the need to add retention labels to folders and the files within those folders. I have seen this done a lot using the SharePoint Online PowerShell Module but in terms of authentication in the modern world it is not so easy to authenticate to that module at site level.

So in steps the mega powerful PnP PowerShell. The method I will demonstrate below will use PnP to apply the retention label to both root Documents & Shared Documents and an alternative way to apply the labels to subfolders too.

Should you be looking to automate this process in bulk or are just looking for an easy way to authenticate without having to respond to MFA prompts. Please see Connect-PnPOnline Unattended Using Azure App-Only Tokens.

Set Retention Label on the Root Folder

$RootLabel = "Default"

# SharePoint Online
Set-PnPLabel -List "Shared Documents" -Label $RootLabel

# OneDrive for Business
Set-PnPLabel -List "Documents" -Label $RootLabel
Read More

Connect-PnPOnline Unattended Using Azure App-Only Tokens

There are lot's of reasons why unattended authentication is handy using modern authentication methods. This is true in Azure, Exchange Online, Azure AD, SharePoint & more. Azure Automation is the main reason I tend to use them but more regularly, I create scripts, functions & modules that will be used by my colleagues. If I set up authentication using a service principal/Azure App registration, I can then pre-configure the less sensitive data within, leaving my colleagues to pass the certificate password, secret or perhaps thumbprint to the script via the console. This keeps the sensitive data safe but takes away they need for the MFA prompts and permission checks.

In this example, I am going to walk through how I set up an Azure App registration that can be used in this way. There is a very helpful post at PnP-PowerShell covering Connect Using App Permissions that is probably worth a read. This approach is more simple but works very well and it uses a self signed certificate. I have found it pretty easy to put the certificate in a shared area making it simple for the code to access when colleagues use my PowerShell offerings too.

Here is the code

$Password = "P4ssW0rd"

$SecPassword = ConvertTo-SecureString -String $Password -AsPlainText -Force

$Params = @{
    Out                 = "C:\temp\LabSPOAccess.pfx" 
    ValidYears          = 30 
    CertificatePassword = $SecPassword 
    CommonName          = "LabSPOAccess" 
    Country             = "GB" 
    State               = "Scotland" 
    Locality            = "Glasgow"

$Cert = New-PnPAzureCertificate @Params
Read More

PowerShell SharePoint PnP: Installing SharePoint PNP PowerShell

Open Windows Powershell as Administrator.

Run the following

Install-Module SharepointPNPPowershellOnline

Type A when prompted.

To verify the version installed type the following:

Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending

Type the following to connect to your SharePoint Online Environment replacing <YourTenant> with your Tenancy alias, e.g alanlearnsstuff12345

Read More

PowerShell SharePoint: Installing SharePoint Online Management Shell

Once upon a time there was a need to download an MSI and to install the SharePoint PowerShell Module that way, however, as all useful and trusted modules do one day it now can be found in the PowerShell Gallery at this linkMicrosoft.Online.SharePoint.PowerShell. If you were still to need it for some reason it can be located here. But don't bother doing that, have a read below and get started using SharePoint Online Management Shell.

So, to install the module, run PowerShell as administrator and type …

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

Then to bring it in to use by sending this command …

Import-Module -Name Microsoft.Online.SharePoint.PowerShell

Now we have the module, installed and imported to the session let's connect …

Read More