我是powershell的初学者。我有一个我创建的自定义 cmdlet。此代码将在最后一行中断:
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
PSSnapInException psEx = null;
runspaceConfiguration.AddPSSnapIn(mySnapin, out psEx);
using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
{
runspace.Open(); // breaks here.
它给了我 Access to registry is not allowed 错误,除非我将上面的代码附在里面:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
});
要访问 SPSecurity,我当然必须带上我的参考资料:Microsoft.Sharepoint。它确实有效,但我的 powershell 代码与 sharepoint 无关。我可以使用更通用的 powershell 安全 dll 来代替 SPSecurity(即使它有效)?我找不到一个。谢谢。