1

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

1

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

2
  • It is asking me for the pwd. Do I need to be the site owner to access the data through CSOM ? – Debuxed Jun 10 '19 at 5:17
  • yes....it totally depends on what you want to do...what operation you do on site with script, user should have proper access. – Siddharth Vaghasia Jun 10 '19 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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