0

I am guessing that Start-Process will be used, but I am uncertain how exactly to accomplish these two things at once.

The user is a local user and is a member of Administrators.

Additionally there can be no user input required.

Update: Here is what I have tried and why it did not work. As Keith Suggested, I tried doing the following:

$passwd = ConvertTo-SecureString -AsPlainText "opensesame" -Force
$cred = new-object system.management.automation.pscredential 'John',$passwd
Start-Process powershell.exe -credential $cred

This did not launch the powershell window in administrator mode. Adding the runas verb does not work because start-process has two completely separate ways to call it, one of which takes -Verb as a parameter and one of which takes -Credential:

Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-Credential <PSCredential>] [-LoadUserProfile] [-NoNewWindow] [-PassThru] [-RedirectStandardError <string>] [-RedirectStandardInput <string>] [-RedirectStandardOutput <string>] [-UseNewEnvironment] [-Wait] [-WorkingDirectory <string>] [<CommonParameters>]

Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-PassThru] [-Verb <string>] [-Wait] [-WindowStyle {<Normal> | <Hidden> | <Minimized> | <Maximized>}] [-WorkingDirectory <string>] [<CommonParameters>]

This means that the following returns an error:

Start-Process powershell.exe -credential $cred -verb runas
Colin B
  • 367
  • 1
  • 4
  • 12

1 Answers1

3

Try this:

$passwd = ConvertTo-SecureString -AsPlainText "opensesame" -Force
$cred = new-object system.management.automation.pscredential 'John',$passwd
Start-Process powershell.exe -credential $cred

This TechNet article has more information on scripts that use credentials.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Yeah, forgot that those two parameters were mutually exclusive. Removed that bit from the answer. I'll look into this a bit more. I take it that UAC is enabled on this system? – Keith Hill Feb 10 '14 at 18:27
  • Yes it is. This is running on an Azure Worker Role, which is why it has the strict automation and user requirements. – Colin B Feb 10 '14 at 18:48