Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run a PowerShell script from a windows batch file. This is a SharePoint related script that uses Import-SPData.

This works without any issue when using USERA's login. However, if I try to run the same batch file from USERB's login, I get the error below:


c:\PS>C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -psconsolefile "
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\P
OWERSHELL\Registration\psconsole.psc1" -command "c:\ps\MyPSScript.ps1"

The local farm is not accessible. Cmdlets with FeatureDependencyId are not regis
Import-SPData : Cannot access the local farm. Verify that the local farm is pro
perly configured, currently available, and that you have the appropriate permis
sions to access the database before trying again.
At C:\ps\Run_MyPSScript.ps1:5 char:18


I made sure that USERB has permissions to the bat and the ps1 files.

I am using PowerShell version 2 and SharePoint Server 2010

share|improve this question

Sharepoint is a beast to deal with. I would supsect UserB doesnt the proper sharepoint permissions and/or access to the content database

I would compare the permission for UserA and UserB at the Windows, Sharepoint, and DB level to look for differences.

share|improve this answer
up vote 0 down vote accepted

Ok, I managed to get this to work.

According to Microsoft:

In order to use Windows PowerShell for SharePoint 2010 Products, a user must be a member of the SharePoint_Shell_Access role on the configuration database and a member of the WSS_ADMIN_WPG local group on the computer where SharePoint 2010 Products is installed.

To do this:

  • Open the SharePoint management shell (run as administrator if you have User Account Control activated)
  • Add SharePoint_Shell_Access role to USERB for the SharePoint configuration database.

Can use the following PowerShell code to do this:

$dbs = Get-SPDatabase; foreach($d in $dbs) {If($"SharePoint_Config")){Add-SPShellAdmin "domain\USERB" -database $d}}
  • Make sure the SharePoint site collection and document library/list (if any) also have the proper permissions for USERB
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .