Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered

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

Import-SPData : Cannot access the local farm. Verify that the local farm is properly configured, currently available, and that you have the appropriate permissions to access the database before trying again.

At C:\ps\Run_MyPSScript.ps1:5 char:18

USERB has permissions to run the bat and the ps1 files.

like image 336
slayernoah Avatar asked Mar 19 '14 20:03

slayernoah


1 Answers

You are assuming, the error is related to permission to either the bat or the powershell file.

The error you get comes from a SP cmdlet, so you have successfully opened the bat file and successfully run the powershell script. Which then throws an error. UserB has not the apropriate rights to the farm. Hence the error:

...and that you have the appropriate permissions to access the database before trying again.

Compare the permissions from UserA and UserB on the farm and the database.

Or you could use a sledgehammer and log into UserA to run the following powershell script:

$db = Get-SPDatabase | Where {$_.Name -eq "SharePoint_ConfigDB"}
Add-SPShellAdmin "domain\UserB" -database $db
like image 114
Marco Avatar answered Oct 02 '22 07:10

Marco