0

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?

1 Answer 1

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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