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

PowerShell

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

Practical PowerShell Logs

All scheduled PowerShell files should generate LOGs.  “Start-Transcript” is a great cmdlet for this.  Adding a few more features can boost operations support.   LOGs answer essentials support questions like:

  • Which parent PS1 generated this LOG?
  • Did script perform needed functions?
  • Any errors?
  • How long did it take?
  • Which user and computer ran the script?

Below is code template I recommend to for scheduled PowerShell jobs to generate a LOG. Key features include:

  • Auto detect current folder and script PS1
  • Create  \LOG\ subfolder
  • Prefix to match parent PS1
  • Suffix with unique date time stamp
  • Elapsed run duration (Days, Hours, Minutes)

Thank you to @ToddKlindt for improvements to formula and elapsed time.  Cheers. 

shades_smile

Video

Code

function Main() {
    ### YOUR CODE HERE
}

# Open Log
$prefix = $MyInvocation.MyCommand.Name
$host.UI.RawUI.WindowTitle = $prefix
$stamp = Get-Date -UFormat "%Y-%m-%d-%H-%M-%S"
Start-Transcript "$PSScriptRoot\log\$prefix-$stamp.log"
$start = Get-Date

Main

# Close Log
$end = Get-Date
$totaltime = $end - $start
Write-Host "`nTime Elapsed: $($totaltime.tostring("hh\:mm\:ss"))"
Stop-Transcript

Download

https://github.com/spjeff/spadmin/blob/master/Practical-PowerShell-LOGs.ps1

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲