The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered (and similar errors)

I think we knew the answer to this already, but it can still catch you out. As a developer I always do everything using some omnipotent user account. Usually that user account is simply called "administrator" - yes, that's me! And that's the account I used to install SharePoint in the first place and do everything else - and before you admin types get on your high horses, it's my development farm and I can do what I like.

Meanwhile, in the real world of administration and operations everybody is doing things properly and using "least privilege" accounts. Professional administrators are surprisingly coy about giving out accounts with administrator privileges.​ But this particular problem is not so much about being a box admin or whatever - it's the rights you have to the SharePoint content databases, and specifically the configuration database. If you try to press on regardless and start doing things like Get-SPSite and so on, you will be rebuffed with "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." Of course you do try again, several times, with the same result. How to get rid of all the red nonsense in the PowerShell window?

Firstly you need to run the PowerShell script as an administrator, which means that the account you intend to use needs to have at least local administrator rights (it doesn't need to be a domain administrator). You may also need to explicitly use the "Run as Administrator" flag/option to start the PowerShell window. Also remember that after your account is given administrator privileges you will need to log in again.

Now you also need to set some permissions in SQL Server, and you could do this by hand. But there is a much easier way. You just need to grant the user account "SharePoint_Shell_Access" privileges in SQL Server using the PowerShell commandlet Add-SPShellAdmin. Obviously you can't just run that command directly as you don't have access. You have to get an existing user that has rights to modify the permissions of the database, such as the account you used to install SharePoint in the first place. This user needs to run the command as follows:

Add-SPShellAdmin Domain\User

If you want to see all the users that have the "SharePoint_Shell_Access" role, use the Get-SPShellAdmin command. You would expect to see your farm account (aka DB access account) in this list as, possibly, the only item. Great; that gives you access to the configuration database, but for most tasks you will probably want access to some other SharePoint database. You could set these explicitly, or you could grab them all and give yourself shall admin rights with the following PowerShell:

Get-SPDatabase | Add-SPShellAdmin domain\user

Some people have suggested that you need to be added to the Farm Administrators group in Central Administration. You can go to the Security group and then Farm Administrators to do this, or use PowerShell. ​This may be necessary to run some commands, but as far as I can tell it is not a factor in the error messages above. Do verify that your account is a member of the site collection administrators group. Even if your account is a Farm Administrator you still need to make sure it is a Site Collection administrator as well.

​​​