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 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?

Thanks.

share|improve this question
add comment

1 Answer

up vote 2 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:

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({ 
    $site = get-spsite ...
    //Your code
}); 
share|improve this answer
add comment

Your Answer

 
discard

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.