试过我在这个问题上找到的代码:PowerShell: Create Local User Account
但是当我执行它时(在Domain Admin帐户的上下文中运行的ISE,在Domain Admins位于本地Adminstrators组的PC上)我收到以下错误:
Exception calling "SetInfo" with "0" argument(s): "Access is denied.
"
At \\servername\scripts\powershell\create-local-user.ps1:6 char:1
+ $LocalAdmin.SetInfo()
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
在这种情况下,为什么我会使用 SetInfo()
方法获得"Access Denied"异常?
1 回答
@Bill_Stewart确定了问题 - 即使我在一个帐户下运行ISE,该帐户通过"runas"脚本具有域管理员权限,即:
runas /user:domain-admin@company.com "powershell_ise.exe"
它仍然无法在启用了UAC的系统上运行(因为我的运行Win7 Pro) - 单击ISE图标,选择"Run as administrator",然后使用(域)管理员帐户进行身份验证 .