AMFTF: Script your SharePoint objects with PnP PowerShell - #ARCHIVED#

This content has been archived. It may no longer be relevant.  

This blog post is part of a series called AMFTF (a message from the field) containing short blog posts about a best practice, a functionality, a how-to and/or something just worth writing a blog post about. Todays topic is about a community initiative called ‘PnP PowerShell’.

Creating SharePoint objects like lists, site columns and groups using the webbrowser can become quite time consuming, especially when working with multiple environments (like development, test and production).

Some time ago, a community initiative started with the goal to offer PowerShell cmdlets to perform complex provisioning and artifact management actions towards SharePoint. For people who are not familiar with PowerShell: PowerShell is a scripting language used for installation, configuration and automation.

This initiative is called: PnP PowerShell

So why is this useful for PowerApps? Well, there are multiple reasons. It allows you to transfer apps more easily from one environment to another because when executed well, all lists and internal column names are equal meaning you do not have to make changes to your app other than connecting the app to the correct SharePoint lists. You can also use it to add demo data or clean up an environments.

PnP PowerShell also allows you to add site columns with display names which already exist. Something I find particular useful for names like ‘Status’, ‘City’ or ‘Company’. The internal name must be unique though so I always add a prefix.

I advice everybody who build apps with SharePoint to investigate PnP PowerShell. You will not regret it.

An example to add a SharePoint list and add a list column to it (after connecting to a site) is given below:

$title = 'PowerApps demo list'
$template = 'GenericList'
$url = 'powerappsdemolist'
$hidden = $false
$enableVersioning = $true
$enableContentTypes = $false
$onQuickLaunch = $true

New-PnPList -Title $title -Template $template -Url $url -Hidden:$hidden -EnableVersioning:$enableVersioning -EnableContentTypes:$enableContentTypes -OnQuickLaunch:$onQuickLaunch

$xml = '<Field
    <Default>Not started</Default>
Add-PnPFieldFromXml -FieldXml $xml -List $title

More information about the initiative can be found here.