InfoPath – search replace URLs within XSN
Need to migrate forms to another URL? But not sure how to update many data connections? Try the script below.
This PowerShell will extract XSN contents to a folder, execute string search replace, and “package” back into CAB format with XSN extension. A simple way to migrate InfoPath forms to another DNS name for scenarios like AAM Alternate Access Mapping redirection and SharePoint major version upgrade (2007 > 2010 > 2013).
Enjoy!

NOTE – Requires CABARC.EXE http://stackoverflow.com/questions/3361928/where-can-i-get-the-cabarc-utility
InfoPath_UpdateDataConnetions.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# Update InfoPath form URLs by extracting CAB and performing search replace Param( [string]$xsnFile ) Write-Host "Prepare folders..." md c:\InfoPath\before md c:\InfoPath\temp md c:\InfoPath\after Write-Host "Clean temp..." Remove-ChildItem c:\InfoPath\temp\*.* -Recurse Write-Host "Extract XSN... $xsnFile" cabarc x "c:\InfoPath\before\$xsnFile" *.* c:\InfoPath\temp\ Write-Host "Replace URL..." $txt = Get-Content c:\InfoPath\temp\Manifest.xsf $txt |% {$_ -replace "//sharepoint/" "//sharepnt07/"} | Out-File -FilePath "c:\InfoPath\temp\Manifest.xsf" -Encoding UTF8 -Force Write-Host "package XSN..." cabarc n "c:\InfoPath\after\$xsnFile" c:\InfoPath\temp\*.* Write-Host "DONE" |