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

link|improve this question
feedback

1 Answer

up vote 6 down vote accepted

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

link|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 at 20:11
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.