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

PNP

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

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! 

shades_smile

Video

Screenshot

ERROR – Initializers are not allowed in ambient contexts.

image

Reference

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲