Can RunWithElevatedPrivileges be used in a PowerShell script?

别等时光非礼了梦想. 提交于 2019-12-24 17:19:51

问题


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.


回答1:


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




回答2:


Yes, it can.

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({ 
    $site = get-spsite "http://localhost/nonfarmadminsitecollection";
}); 

Be careful with that. Since you are impersonating the process account, you lose information about the user in the audit trails.




回答3:


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.



来源:https://stackoverflow.com/questions/2154750/can-runwithelevatedprivileges-be-used-in-a-powershell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!