I'm writing some powershell and I can easily access local farm resources but I would like to access a remote farm? Is this possible?

The code works below when targeting the local server:

$site = new-object Microsoft.SharePoint.SPSite("http://mylocalserver")
$web = $site.RootWeb
Write-Host $web.Title

but it gives the error below for a remote farm:

The Web application at http://myotherfarm.localdomain could not be found.


I have never needed to do this personally but I would imagine it could be done via the Invoke-Command statement that specifically provides for remote execution of commands. Something along the lines of :

Invoke-Command -Computername ServerInOtherSPFarm -Scriptblock { ... your code here ... }

Naturally, the account that powershell is running under would need permissions on the remote server.


When using the SharePoint Server Object model all the access is "directly" to the databases of the Farm you're working with.

If you don't specify which farm, then it'll be the local farm (specified in the registry of the server).

If you REALLY want you can access another farm (provided you have access) by using SPFarm.Open and specify a connection string to the Configuration database of that farm. You'll then be able to walk the chain:

Farm -> WebServices -> WebApplications -> Site Collections

But you all the time have to access the next object from one you got in that chain starting with the SPFarm returned by SPFarm.Open or you'll try to access the current farm AND it's VERY easy to make a mistake.

So you proably want to look at using remote PowerShell like suggested by @Dave

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.