Tag Archives: PNP
How to switch to PNP.PowerShell (PS7) from SharepointPnPPowerShellOnline (PS5.1)
Wanted to record a quick demo for how to switch from the current established “SharepointPnPPowerShellOnline” module into new “PNP.PowerShell” module based on .Net Core. Shout out to @ToddKlindt for the great blog post. Cmdlets and references below. Cheers ![]()
Video
Source Code
Uninstall-Module SharePointPnPPowerShellOnline –AllVersions Install-Module PnP.PowerShell –AllowPrerelease Register-PnPManagementShellAccess
References

VIDEO – PowerShell PNP to parse InfoPath XML Attachments
Wanted to share quick tutorial on how to parse InfoPath attachment XML. Source Form Library contains XML with Base64 encoded attachments which we can parse into local TEMP folder and then upload to destination Document Library. Extract filename and file content for each InfoPath attachment XML node. Save into subfolders and match original file naming. Helpful for Office 365 migration and scenarios where InfoPath client is no longer available and users prefer to view attachments directly.
Video, screenshots, and source code below.
GitHub Repo
Video
Screenshots
VIDEO – Load PNP the Right Way
Quick post about detecting if PowerShell PNP is available on the local PC and installing is missing (for new systems) to make PS1 script more portable across servers.(1) Detect command (2) Install module if missing (3) Import module. Cheers
![]()
Video
Code
# Load PNP module, the right way
Add-Type -Assembly "System.IO.Compression.FileSystem" -ErrorAction SilentlyContinue | Out-Null
$pnp = Get-Command Connect-PnPOnline -ErrorAction SilentlyContinue
if (!$pnp) {
Install-Module "SharePointPnPPowerShellOnline" -Force
}
Import-Module "SharePointPnPPowerShellOnline" -ErrorAction SilentlyContinue | Out-Null
References
VIDEO – Toggle Required Fields OFF
When making bulk data changes to SharePoint List or Library you may need to temporarily turn off Required fields. Opening this can allow us to import records, apply changes, and modify metadata without prompting that required fields are missing. PowerShell below can help disable all Required fields OFF. Script generates a CSV snapshot of prior configuration during run. CSV can be used to restore original configuration for which fields are Required.
VIDEO
PowerShell Code
[CmdletBinding()]
param (
[bool]$required,
[string]$restoreFilename
)
# Module
Import-Module "SharePointPnPPowerShellOnline" -ErrorAction "SilentlyContinue" | Out-Null
# Config
$appid = "APP ID HERE"
$appsecret = "APP SECRET HERE"
function Main() {
# Connect
Connect-PnPOnline -Url "https://tenant.sharepoint.com/" -AppId $appid -AppSecret $appsecret
$ctx = Get-PnPContext
$list = Get-PnPList "Test"
$list
if ($restoreFilename) {
# ENABLE Required Fields
$csv = Import-Csv $restoreFilename
$fields = Get-PnPField -List $list
foreach ($row in $csv) {
$row.Guid
$f = $fields | ? { $_.Id -eq $row.Guid }
$f.Required = $true
$f.Update()
}
$ctx.ExecuteQuery()
}
else {
# DISABLE Required Fields
$coll = @()
$guid = (New-Guid).ToString()
$fields = Get-PnPField -List $list
foreach ($f in $fields) {
if ($f.Required) {
Write-Host "CHANGED FIELD $($f.Title) NOT REQUIRED"
$f.Required = $false
$f.Update()
$coll += $f.Id
}
}
$ctx.ExecuteQuery()
$coll | Export-Csv "PNPToggleRequiredField-$guid.csv"
}
}
# Main
Main
GitHub Link
References
VIDEO – Attempt to build Angular CLI with PNP JS
Recently attempted to create a command line interface (CLI) project with Angular 6 and SP-PNP-JS library for data access. Followed tutorial by @arustacean at https://medium.com/ng-sp/angular-spa-in-sharepoint-3e7195741460 but with using the latest version of each library.
GitHub source code available at https://github.com/spjeff/sp-ng
However, received strange errors on the web pack TypeScript build process. Attached video shows the troubleshooting process. Cheers! ![]()
Video
Screenshot
ERROR – Initializers are not allowed in ambient contexts.
Reference
VIDEO – Disable Legacy Auth & Connect PNP
Even with Legacy auth disabled, you can successfully run Connect-PNPOnline. Video demo shows changing SPO tenant security, then how to register new AppId for Connect-PNPOnline access to all site collections in tenant. The “AppRegNew” and “AppInv” ASPX pages can be used to establish authentication channel for PowerShell work in PNP on Office 365 tenants where Legacy Auth is disabled. Cheers! ![]()
Video
Code
# Check SPO Connect-SPOService "https://spjeff-admin.sharepoint.com" Get-SPOTenant | Select *legacy* | ft # 2) Disable Legacy Set-SPOTenant -LegacyAuthProtocolsEnabled $false Get-SPOTenant | Select *legacy* | ft # 3) Register App # https://spjeff-admin.sharepoint.com/_layouts/15/appregnew.aspx # 4) Invite App # https://spjeff-admin.sharepoint.com/_layouts/15/appinv.aspx # 5) PNP Login Connect-PNPOnline -AppId "e419e703-5293-402c-bb70-3aff593b850b" -AppSecret "secret-here" $w = Get-PNPWeb Get-PNPList -Web $w
References
- http://www.sparkhound.com/blog/office-365-modern-authentication
- https://github.com/SharePoint/PnP-PowerShell/blob/master/Commands/Samples/Connections.ps1
- https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/set-spotenant?view=sharepoint-ps
- https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs
- https://medium.com/ng-sp/sharepoint-add-in-permission-xml-cheat-sheet-64b87d8d7600
-LegacyAuthProtocolsEnabled
By default this value is set to $True. Setting this parameter prevents Office clients using non-modern authentication protocols from accessing SharePoint Online resources. A value of True- Enables Office clients using non-modern authentication protocols (such as, Forms-Based Authentication (FBA) or Identity Client Runtime Library (IDCRL)) to access SharePoint resources. A value of False-Prevents Office clients using non-modern authentication protocols from accessing SharePoint Online resources. Note This may also prevent third-party apps from accessing SharePoint Online resources. Also, this will also block apps using the SharePointOnlineCredentials class to access SharePoint Online resources. For additional information about SharePointOnlineCredentials, see SharePointOnlineCredentials class.
