Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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>ExecMyPowershellScript.bat

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
tered.
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

2 Answers 2

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.

http://technet.microsoft.com/en-us/library/ff607596%28v=office.14%29.aspx

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($d.name.contains("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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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