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

Flow: Create SharePoint List Yes/No Fields Using REST API with Power Automate

When you have an existing SharePoint list or if you have created one using the method described in Create SharePoint List REST API with Power Automate, you will then want to populate it with some fields.

There are several FieldTypeKinds, at least 31 and you kind find more information on them at this linkFieldType Members.

In this post, I will cover another commonly used FieldType in SharePoint, the "Yes/No" field.

Here is the complete Flow:

Read More

Flow: Create SharePoint List Choice Fields Using REST API with Power Automate

When you have an existing SharePoint list or if you have created one using the method described in Create SharePoint List REST API with Power Automate, you will then want to populate it with some fields.

There are several FieldTypeKinds, at least 31 and you kind find more information on them at this linkFieldType Members.

In this post, I will cover another commonly used FieldType in SharePoint, the "choice" field.

Here is the complete Flow:

Read More