Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

Thanks

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer
1  
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

 
discard

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