Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

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

shades_smile

Video

Source Code

Uninstall-Module SharePointPnPPowerShellOnline –AllVersions
Install-Module PnP.PowerShell –AllowPrerelease
Register-PnPManagementShellAccess

References

PnP PowerShell RoadMap

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. 

Cheers

shades_smile

GitHub Repo

Video

Screenshots

SNAGHTML46f8607
image
image
image
image

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

shades_smile

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.

Cheers

shades_smile

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

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲