Friday 7 December 2012

Using PowerShell to Create Multiple Send to Connections In SharePoint 2010


So having come across a scenario where I was asked to create multiple send to connections for a Records centre design, I was sure it was possible to use PowerShell to help us out here yet again!

Now I had seen basic PowerShell scripts to create a single send to rule, so by tweaking this slightly to use a source XML file containing all of the values for my multiple send to rules you can create as many as required with minimal administrative effort.
The PowerShell and XML format are below.

PowerShell:

[xml]$SendTos = gc $pwd\sendtorule.xml

        $SendTos.SendTos | % {
                $webapp = Get-SPWebApplication $_.WebApplicationUrl.TrimEnd("/")  

                $_.SendTo | % {
                                $SendTo = $_

                $officialFileHostTemp = $webapp.OfficialFileHosts | ? {
                                 $_.OfficialFileName -eq $SendTo.OfficialFileName
                  }

                 if($officialFileHostTemp -eq $null)
                  {
    
 [Microsoft.SharePoint.SPOfficialFileHost] $officialFileHost = New-Object "Microsoft.SharePoint.SPOfficialFileHost"
          $officialFileHost.Action = [Enum]::Parse([Microsoft.SharePoint.SPOfficialFileAction], $SendTo.Action)
          $officialFileHost.Explanation = $SendTo.Explanation
          $officialFileHost.OfficialFileName = $SendTo.OfficialFileName
          $officialFileHost.OfficialFileUrl = $url+$SendTo.OfficialFileUrl
          $officialFileHost.ShowOnSendToMenu = [bool]::Parse($SendTo.ShowOnSendToMenu)
          $webapp.OfficialFileHosts.Add($officialFileHost)
          $webapp.Update()
    }
       $officialFileHostTemp = $null
    }
 }
    


XML Structure

 <SendTos WebApplicationUrl="http://WebAppURL">
                <SendTo>
                                <Action>Move</Action>
                               <Explanation>Move the HR Records site collection</Explanation>
                               <OfficialFileName>Move to HR Records</OfficialFileName>
                               <OfficialFileUrl>http://siteURL/_vti_bin/officialfile.asmx</OfficialFileUrl>
                               <ShowOnSendToMenu>true</ShowOnSendToMenu>
        </SendTo>
                 <SendTo>
                              <Action>Move</Action>
                              <Explanation>Move the IT Records site collection</Explanation>
                              <OfficialFileName>Move to IT Records</OfficialFileName>
                              <OfficialFileUrl>http://siteURL/_vti_bin/officialfile.asmx</OfficialFileUrl>
                              <ShowOnSendToMenu>true</ShowOnSendToMenu>
       </SendTo>

</SendTos>



Thanks for Reading,

Matt

No comments:

Post a Comment