Error The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered
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
slayernoah
SO has helped me SO much. I want to give back when I can. And I am #SOreadytohelp http://stackoverflow.com/users/1710577/slayernoah #SOreadytohelp
Updated on March 10, 2020Comments
-
slayernoah about 4 years
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 fromUSERB
'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 thebat
and theps1
files. -
slayernoah about 10 yearsThanks. My SharePoint config database name was SharePoint_Config_<random_letters_and_numbers> so I used
$dbs = Get-SPDatabase; foreach($d in $dbs) {If($d.name.contains("SharePoint_Config")){Add-SPShellAdmin "domain\USERB" -database $d}}
-
ΩmegaMan about 7 yearsUse
$dbs = Get-SPDatabase | Where {$_.Name -like "SharePoint_Config*" };
instead to find the target db. -
Mohamed over 3 yearsI got this problem due to PowerShell version The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered in SharePoint