Reputation: 5821
I need to run a Powershell script completely automated, but it needs to be run as an administrator. I am open to doing this with either Powershell commads or C# coding. Which ever provides me the answer first. I have been looking around online for what seems like forever, but I am still unsuccessful...
For C# I have tried this, but do not have a domain name and it seems to throw errors: http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User
For Powershell I have tried using Start-Process -credential "username"
but there doesn't seem to be a way for me to enter the password portion and if i try to do:
Start-Process -credential "username", "Password"
or
Start-Process -credential "username" "Password"
I get an error saying Start-Process : Cannot process argument transformation on parameter 'Credential'.
I have also tried using Start-Process Powershell -Verb runAs
, but that still brings up UAC and I would still need to run the window in the background (which isn't my main concern since i can just use -NoNewWindow
for that).
I am relatively new with Powershell and it would be really helpful if anybody had any ideas as to how I would go about doing this.
Thank you!
Upvotes: 1
Views: 7256
Reputation: 3311
Running as an administrator won't solve much if the script isn't running elevated, which is what -RunAs
does. If you don't want it to prompt at all then disable UAC, even running the script as a user that's a member of the Administrators group will still prompt if UAC isn't disabled, or your script will fail if it isn't running with elevated privileges.
Upvotes: 1