Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer 1

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 - msdn.microsoft.com/en-us/library/lists%28v=office.12%29.aspx –  ToddersLegrande Feb 28 '12 at 14:48
add comment

Your Answer

 
discard

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.