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 have a couple MOSS dev environments that need to have a script to restore the content databases from production. Part of the script has to set the site collection administrators to the user of the dev environment, as after being restored the sca's are changed to whatever production was.

I have a commandlet that will work, though only when run by an existing site collection admin. I know you can reference the SharePoint API through powershell, but the syntax of RunWithElevatedPrivileges requires the use of a delegate as the parameter. How would I do this in powershell?


share|improve this question
up vote 4 down vote accepted

When you run PowerShell script, you can run the script itself with Site Collection Admin credentials or with app pool credentials. You can do this by holding Shift + Right-Click and then select "Run as different user".

I prefer to use above approach but if you want to use RunWithElevatedPrivileges, you can try following:

    $site = get-spsite ...
    //Your code
share|improve this answer

Your Answer


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

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