2

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.

5

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
}); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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