As there are so many post related to the error. So just wanted to throw my ball in the court.
So lets get started :)
When ever you are running any powershell cmd or script you are getting below Error.
1. The account which you are using to run the powershell should have below access on SharePoint Config DB
- DB_Owner access
Add-SPShellAdmin -username DOMAIN\Username
3. If above doesn't help you and you are still facing the error. You have to run PowerShell As an Administrator.
Hope this post help.
Happy SharePointing :)