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?