Get SharePoint Online list templates with PowerShell

This is part 6 of 10 where we will be getting the SharePoint Online list templates with PowerShell. This is part of the following series:

We will be collecting all available web templates in part 1 so we can use this to create a new site in part 2. In part 3 we will be creating a web for the newly created site. We then want to create a couple of site columns in part 4 which we will combine to a content type in part 5. This content type will be added (part 8) to our newly created document library in part 7 using a list template from part 6. After everything is set we will be setting the view in part 9 for this list to show the added columns we got from adding the content type. We only want to set permissions for myself so I’ll will be breaking the inheritance and setting permissions in part 10.

 Get SharePoint Online list templates with PowerShell

This script will get the SharePoint Online list templates with PowerShell. Microsoft can add list templates on future updates so I suggest to run this script from time to time. We will first start by opening the SharePoint Online Management Shell as administrator which can be downloaded at https://www.microsoft.com/en-us/download/details.aspx?id=35588.

image

You will need to change the first variables to match your Office 365 tenant and copy this bit to PowerShell.

function get-SPOnlineListTemplates {
    #variables that needs to be set before starting the script
    $siteURL = "https://spfire.sharepoint.com/sites/blogdemo"
    $adminUrl = "https://spfire-admin.sharepoint.com"
    $userName = "mpadmin@spfire.onmicrosoft.com"
    
    # Let the user fill in their password in the PowerShell window
    $password = Read-Host "Please enter the password for $($userName)" -AsSecureString
    
    # set SharePoint Online credentials
    $SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)
        
    # Creating client context object
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
    $context.credentials = $SPOCredentials
 $listTemplates = $context.web.listtemplates
 $context.load($listTemplates)
    
    #send the request containing all operations to the server
    try{
        $context.executeQuery()
        write-host "info: Loaded list templates" -foregroundcolor green
    }
    catch{
        write-host "info: $($_.Exception.Message)" -foregroundcolor red
    }
     
 #List available templates
 $listTemplates | select baseType, Description, ListTemplateTypeKind | ft –wrap
}
get-SPOnlineListTemplates

image

You will be asked to enter the password and press enter

image

We are going to use the ListTemplateTypeKind property in our next post.

Tips

You can add out-file <location> to the script to write the output to a txt file.

Leave a Reply

Your email address will not be published. Required fields are marked *