Wednesday, July 20, 2011

How to create send to connection with PowerShell?

Send to connection is used in many seniors, so being able to deploy them through PowerShell is a must and it is in this way you do it:

First the XML configuration file, SendTos tag can be added multiple times if you have several applications. Under the SendTos tag is SendTo which is the connection itself. A send to consist of an Action, which can Copy, Move, or Link. Explanation which is the description for sending the link. Official filename is the name or title of sending the link. OfficialFileUrl is the URL of the site as the document to be sent, N.B. Remember that the content organizer feature must be enabled on the site. ShowOnSendToMenu is whether it should be shown in the document context menu.

  1. <SendTos WebApplicationUrl="http://win-l2sfc3oetnn/">
  2. <SendTo>
  3. <Action>Move</Action>
  4. <Explanation>Move the document to 'a' site collection</Explanation>
  5. <OfficialFileName>Move to 'a'</OfficialFileName>
  6. <OfficialFileUrl>/docid/a/_vti_bin/officialfile.asmx</OfficialFileUrl>
  7. <ShowOnSendToMenu>false</ShowOnSendToMenu>
  8. </SendTo>
  9. </SendTos>

The second part, is the PowerShell, where I loops thought the to sends tags and grab the web application. Then I test whether the connection already exists, if not I create it by adding a Microsoft.SharePoint.SPOfficialFileHost to OfficialFileHosts collection located on the web application.

  1. [xml]$SendTos = gc $pwd\sendto.xml
  2.  
  3. $SendTos.SendTos | % {
  4. $webapp = Get-SPWebApplication $_.WebApplicationUrl.TrimEnd("/")
  5.  
  6. $_.SendTo | % {
  7. $SendTo = $_
  8.  
  9. $officialFileHostTemp = $webapp.OfficialFileHosts | ? {
  10. $_.OfficialFileName -eq $SendTo.OfficialFileName
  11. }
  12.  
  13. if($officialFileHostTemp -eq $null)
  14. {
  15. [Microsoft.SharePoint.SPOfficialFileHost] $officialFileHost = New-Object "Microsoft.SharePoint.SPOfficialFileHost"
  16. $officialFileHost.Action = [Enum]::Parse([Microsoft.SharePoint.SPOfficialFileAction], $SendTo.Action)
  17. $officialFileHost.Explanation = $SendTo.Explanation
  18. $officialFileHost.OfficialFileName = $SendTo.OfficialFileName
  19. $officialFileHost.OfficialFileUrl = $url+$SendTo.OfficialFileUrl
  20. $officialFileHost.ShowOnSendToMenu = [bool]::Parse($SendTo.ShowOnSendToMenu)
  21. $webapp.OfficialFileHosts.Add($officialFileHost)
  22. $webapp.Update()
  23. }
  24. $officialFileHostTemp = $null
  25. }
  26. }

No comments:

Post a Comment

Post a Comment