I'm trying to fetch the groups, users and roles from a site collection a server to another site collection on another server. I'm trying to get the data using Powershell's Get-SpSite <site url>

Unfortunately I'm unable to return the results while accessing the site collection residing on another server. I'm unsure if this is allowed or can be achieved.

enter image description here

有帮助吗?

解决方案

Get-SpSite is Server object model and it would connect only to sites on Same SharePoint farm.

To connect to different site collection on different farm you have to use client object model. Below is example of same with powershell.

Idea here is to use SharePoint.Client.dll and Runtime.dll. load dll in powershell and use typical CSOM methods to connect to site and get data.

$loc = "C:\Users\Bram\Downloads\SharePoint" # Location of DLL's
$siteUrl = "https://contoso.sharepoint.com"
$loginname = "bram@contoso.onmicrosoft.com"

Set-Location $loc

Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")

Write-Host "Please enter password for $($siteUrl):"
$pwd = Read-Host -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
# Remove or replace line below to change authentication method
$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)

$web = $ctx.Web 
$ctx.Load($web) 
$ctx.ExecuteQuery() 

Write-Host " Current web title is '$($web.Title)', $($web.Url)"

Ref link

许可以下: CC-BY-SA归因
scroll top