SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to synchronize certain documents between 2 Doclibs on different SharePoint Farms. This is a 'one-way-sync' meaning all changes should be replicated from A to B, not from B to A. You can identify these file because they have a field turned to $true.

$listItem["SyncToExtranet"] -eq $true

I have tried to do this in SharePoint and came up with the following:

$siteCollection = Get-SPSite "http://myInternalSite/"
foreach($spWeb in $siteCollection.AllWebs)
    foreach($list in $spweb.Lists)
        if(($list.BaseType -eq "DocumentLibrary") -and ($list.IsCatalog -eq $false))
                foreach ($listItem in $list.Items)
                    $FileName = $listItem.Name
                    $ToBeSynced =$listItem["SyncToExtranet"]
                    if($ToBeSynced -eq "True")
                        $siteCollectionExternal = Get-SPSite "https://MyExternalSite"

                        $docLibExternal = spWebExternal.Lists[$list.Title]
                        foreach ($ExternalListItem in $docLibExternal.Items)
                            Write-Host $ExternalListItem.Name

But I cannot connect to the remote site. It throws the following error:

Get-SPSite : Cannot find an SPSite object with Id or Url: https://MyExternalSite.

Is there another way to do this?

share|improve this question

You are going to have to use web services. You can't use the SharePoint API unless the code is running from the farm you are trying to access.

In this case it looks like you are running the code from http://myInternalSite/ and remotely accessing https://MyExternalSite which is not possible directly through the API.

SharePoint provides many web services out of the box and this is a list of those included in WSS for starters (You get more with the paid, and 2010 versions of SharePoint). If the out of the box web services don't suit your needs you can write your own.

share|improve this answer
Specifically you may want to take a look at the Lists web service - – SpartanDonut Feb 28 '12 at 14:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.