SharePoint 2013 – Create or export and import Send To Connections using Powershell
SharePoint 2013 – Create or export and import Send To Connections using Powershell
You can use the following Powershell script to create or export and import new Send To Connections as xml file using Powershell.
This can be useful to make a backup from your current Send To Connections or if you need to setup another environment. (e.g. copying Send To Connections from Production to Development environment)
$webApps = Get-SPWebApplication $xmlOutputPath = <TargetXmlOutputPath> $xmlImportPath = <SourceXmlInputPath> Function Export-SendToConnections([string]$XmlOutputPath) { if(!(Test-Path -Path $XmlOutputPath)) { New-Item -ItemType Directory -Force -Path $XmlOutputPath } $xmlWriter = New-Object System.XMl.XmlTextWriter($xmlOutputPath,$Null) $xmlWriter.Formatting = 'Indented' $xmlWriter.Indentation = 1 $XmlWriter.IndentChar = "`t" $xmlWriter.WriteStartDocument() $xmlWriter.WriteComment('List of exported Send To Connections') $xmlWriter.WriteStartElement('SendToConnections') foreach($webApp in $webApps) { $xmlWriter.WriteStartElement("SendTos") $xmlWriter.WriteAttributeString("WebApplicationUrl", $webApp.Url) foreach($fileHost in $webApp.OfficialFileHosts) { $xmlWriter.WriteStartElement("SendTo") $xmlWriter.WriteElementString("Action",$fileHost.Action) $xmlWriter.WriteElementString("Explanation",$fileHost.Explanation) $xmlWriter.WriteElementString("OfficialFileName",$fileHost.OfficialFileName) $xmlWriter.WriteElementString("OfficialFileUrl",$fileHost.OfficialFileUrl) $xmlWriter.WriteElementString("ShowOnSendToMenu",$fileHost.ShowOnSendToMenu) $xmlWriter.WriteEndElement() } $xmlWriter.WriteEndElement() } $xmlWriter.WriteEndElement() $xmlWriter.WriteEndDocument() $xmlWriter.Flush() $xmlWriter.Close() } Function Import-SendToConnections([string]$XmlInputPath) { if($XmlInputPath -eq $null -or $XmlInputPath -eq '' -or !(Test-Path -Path $XmlInputPath)) { throw [System.IO.FileNotFoundException] "Path '$XmlInputPath' not found or empty." } [xml]$xmlInput = Get-Content -Path $XmlInputPath $connections = $xmlInput.SendToConnections.ChildNodes foreach($sendToConnections in $connections) { $webApp = Get-SPWebApplication -Identity $sendToConnections.WebApplicationUrl if($webApp -ne $null) { foreach($sendToConnection in $sendToConnections.ChildNodes) { $fileHost = $webApp.OfficialFileHosts | ? { $_.OfficialFileName.ToLower() -eq $sendToConnection.OfficialFileName.ToLower() } if($fileHost -eq $null) { [Microsoft.SharePoint.SPOfficialFileHost] $newFileHost = New-Object "Microsoft.SharePoint.SPOfficialFileHost" $newFileHost.Action = [Enum]::Parse([Microsoft.SharePoint.SPOfficialFileAction], $sendToConnection.Action) $newFileHost.Explanation = $sendToConnection.Explanation $newFileHost.OfficialFileName = $sendToConnection.OfficialFileName $newFileHost.OfficialFileUrl = $sendToConnection.OfficialFileUrl $newFileHost.ShowOnSendToMenu = [bool]::Parse($sendToConnection.ShowOnSendToMenu) $webApp.OfficialFileHosts.Add($newFileHost) $webApp.Update() Write-Host "Successfully added new file host for:" $newFileHost.OfficialFileName "on" $webApp.Name } } } } } # Export Example: Export-SendToConnections -XmlOutputPath $xmlOutputPath # Import Example: Import-SendToConnections -XmlInputPath $xmlImportPath