Error Local farm is not available. Cmdlets with FeatureDependencyId 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 problems when using USERA login. However, if I try to run the same batch file from USERB login, I get the following error:

 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" 

Local farm is not available. Cmdlets with FeatureDependencyId are not registered.

Import-SPData: Unable to access the local farm. Ensure that the local farm is configured correctly, is 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 bat and ps1 .

+7
batch-file sharepoint sharepoint-2010
source share
1 answer

The error is assumed to be related to permission either to the flying station or to the powershell file.

The error you get comes from the SP cmdlet, so you have successfully opened the bat file and successfully executed the powershell script command. Which then throws an error. UserB does not have the appropriate rights to the farm. Hence the error:

... and that you have the appropriate permissions to access before retrying.

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

Or you can use a sledgehammer and log in to UserA to run the following powershell script:

 $db = Get-SPDatabase | Where {$_.Name -eq "SharePoint_ConfigDB"} Add-SPShellAdmin "domain\UserB" -database $db 
+7
source share

All Articles