Its a common SharePoint Administrator's pitfall - Forget to run PowerShell script using "Run as Administrator" option, failing so could lead to many *weird* issues while running PowerShell scripts in SharePoint, such as: "The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.".
Solution:
Solution is pretty simple! just right click the SharePoint 2013 PowerShell Snap-in and choose the option "Run as Administrator".
![run as administrator powershell script]()
Enable "Run as Administrator" elevated privilege for SharePoint 2013 Management Shell by default:
To run PowerShell script as administrator automatically, Create a shortcut to your PowerShell console on your desktop
![powershell script always run as administrator]()
Now you can run PowerShell in elevated mode by simply double-clicking the new shortcut on your desktop.
Run PowerShell as administrator in scheduled tasks:
If you are scheduling a PowerShell script, make sure you select the "Run With Highest Privileges" check box. Otherwise your scheduled task which invokes a UAC prompt may fail to run unattended.
Handle Run as Administrator with in PowerShell script:
Lets handle it in our PowerShell code itself, even you forget to use "Run as Administrator" option!
Run as a Different User in PowerShell scripts:
How to run PowerShell as administrator from the command line?
To run PowerShell as administrator in command line:
Solution:
Solution is pretty simple! just right click the SharePoint 2013 PowerShell Snap-in and choose the option "Run as Administrator".

Enable "Run as Administrator" elevated privilege for SharePoint 2013 Management Shell by default:
To run PowerShell script as administrator automatically, Create a shortcut to your PowerShell console on your desktop
- Right-click the "SharePoint 2013 Management Shell" shortcut and click Properties
- Click "Advanced" button under Shortcut tab
- Enable "Run as Administrator" and click on "OK" button.

Now you can run PowerShell in elevated mode by simply double-clicking the new shortcut on your desktop.
Run PowerShell as administrator in scheduled tasks:
If you are scheduling a PowerShell script, make sure you select the "Run With Highest Privileges" check box. Otherwise your scheduled task which invokes a UAC prompt may fail to run unattended.
Handle Run as Administrator with in PowerShell script:
Lets handle it in our PowerShell code itself, even you forget to use "Run as Administrator" option!
Function Check-RunAsAdministrator()add this code at the beginning of your script.
{
#Get current user context
$CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
#Check user is running the script is member of Administrator Group
if($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator))
{
Write-host "Script is running with Administrator privileges!"
}
else
{
#Create a new Elevated process to Start PowerShell
$ElevatedProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter
$ElevatedProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"
#Set the Process to elevated
$ElevatedProcess.Verb = "runas"
#Start the new elevated process
[System.Diagnostics.Process]::Start($ElevatedProcess)
#Exit from the current, unelevated, process
Exit
}
}
#Check Script is running with Elevated Privileges
Check-RunAsAdministrator
#Place your script here.
write-host "Welcome"
Run as a Different User in PowerShell scripts:
$credential = New-Object System.Management.Automation.PsCredential("Domain\UserID", (ConvertTo-SecureString "Password" -AsPlainText -Force))
Start-Process powershell -Credential $credential -NoNewWindow
How to run PowerShell as administrator from the command line?
To run PowerShell as administrator in command line:
- Type : PowerShell to enter into PowerShell console
- Now, Type: Start-Process PowerShell -Verb RunAs
- .Net framework version compatibility (SharePoint 2010 isn't compatible with .Net Framework 4.xx), Append "-version 2" to the command line to resolve.
- Logged in Administrator may not be a member of "SharePoint_Shell_Access" role. (Run "Add-SPShellAdmin" cmdlet to resolve - http://www.sharepointdiary.com/2014/07/the-local-farm-is-not-accessible-cmdlets-with-featuredependencyid-are-not-registered-powershell-error.html )
Another solution to address this issue: Disable UAC! Here is how - How to Disable UAC in Windows Server 2012/2008