Getting an "Access Denied" error when executing PS code as an Administrator

14.7k views Asked by At

Tried the code I found on this SO question: PowerShell: Create Local User Account

But when I execute it (in ISE running in the context of a Domain Admin acct, on a PC where Domain Admins are in the local Adminstrators group) I'm getting the following error:

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

Why would I be getting an "Access Denied" exception with the SetInfo() method in this case?

1

There are 1 answers

1
Will Dennis On

@Bill_Stewart identified the problem -- even though I was running ISE under an account that has domain admin priv's via a "runas" script, i.e.: runas /user:[email protected] "powershell_ise.exe" it still will not work on systems with UAC enabled (as mine is, running Win7 Pro) without right-clicking the ISE icon, selecting "Run as administrator" and then authenticating with a (domain) admin account.