SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to perform some tasks on user profiles and so, need to connect with different permissions using an account created for that. And, I am doing this with Powershell.

Try {
    $site = Get-SPSite $mySiteUrl
    $context = Get-SPServiceContext $site
    $profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
Catch {
    "Error getting Get-SPSite"
    $site = $null

This produces an error:

Error getting Get-SPSite
Get-SPSite : 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:\scripts\ConnectScripts\TEAResumes\uploadTeaCvsToSharepoint.ps1:19 char:20
+     $site = Get-SPSite <<<<  $mySiteUrl
    + CategoryInfo          : InvalidData: (Microsoft.Share...SPCmdletGetSite:SPCmdletGetSite) [Get-SPSite], SPCmdletException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetSite

So, I was wondering how authenticate with different creds?


share|improve this question
up vote 5 down vote accepted

You need to run the script as a different user. Using runas or ShellRunAs.

share|improve this answer
You can also hold shift down and right click on the link to start PowerShell and the option "Run as different user" will appear in the menu – Dave Wise Feb 2 '12 at 20:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.