views:

93

answers:

2

If yes, please give an example.

UPDATE:

I have a PowerShell script that iterates through all site collections within selected Web application and changes the siteCollection.Audit.AuditFlags property. It works fine on my development machine, but the siteCollection.Audit.Update() command fails with Access is denied error on the production server, even though I am trying to run it as a user who is a farm administrator.

+2  A: 

Run powershell as an administrator or as your webapp application pool user.

Janis Veinbergs
@chopeen - farm administrator and webapp application pool user are probably not be the same thing, and they probably don't have the same rights to the SQL Server instance either.
Goyuix
This does not answer the actual question (wheter RunWithElevatedPrivileges can be used in PowerShell or not), but it solves my problem - the script works fine when executed as Web application pool user.
Marek Grzenkowicz
no, runwithelevatedprivilegs can NOT be used on powershell. why? because there is no underlying impersonation going on for a RevertToSelf call; in simpler terms, powershell is not running on top of an application pool, so the call makes no sense.
x0n
+1  A: 

RunWithElevatedPrivs uses the application pool user on regular web apps, not farm admin. If the elevation happens on central administration, then it's a farm admin account. I assume you are doing this on regular webapps, so launch powershell as the app pool acount.

-Oisin

x0n