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!  shades_smile





# Update InfoPath form URLs by extracting CAB and performing search replace
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"


Return to Top ▲Return to Top ▲