I have written a powershell script which generates a "EULA" type popup which the user has to agree to.

It does this at logon by running as a scheduled task for a user (non-admin) account. It needs to run elevated, so I am using the following script to run it elevated:

$pw= convertto-securestring "myPassw0rd" -asplaintext –force
$credential = new-object -typename system.management.automation.pscredential -argumentlist "-default-",$pw
$localArgs = "/c Powershell c:\scripts\myScript.ps1" 

[System.Diagnostics.Process]::Start("cmd.exe", $localArgs, "Administrator", $credential.Password, $computer)

(I will be encrypting the password to make it slightly more secure, but that's not relevant to this question.)

Anyway - my problem is that when the script is called it displays the command prompt window behind my "pretty" EULA popup.

Is there a way to hide / minimise the command window?



  • Do you want the PowerShell script or the cmd.exe prompt to be hidden? – Mark Schill Jun 27 '10 at 21:24
  • Why do you even run a PowerShell script by calling cmd which then starts PowerShell? That sounds like at least two levels of indirection too much. – Joey Jun 27 '10 at 21:35
  • @Mark - I want the command window to be hidden – Ben Jun 27 '10 at 22:22
  • @Johannes - That was the only way I could successfully pass Admin credentials to it, by running the above "wrapper" script – Ben Jun 27 '10 at 22:24
  • Taken a look at Start-Process? – Joey Jun 28 '10 at 9:32

This should be what you need:

$Process = new-Object System.Diagnostics.Process

You can use the Start-Process cmdlet (PowerShell 2.0):

Start-Process cmd.exe -Credential $credential -WindowStyle Hidden -WorkingDirectory ... -ArgumentList...

  • Think this is 90% there, but am getting " Parameter set cannot be resolved using the specified named parameters" when I add the -Credential argument. – Ben Jun 29 '10 at 10:44

You can't use -Credential and -WindowStyle parameters together with PowerShell v2, you either need PowerShell v3 or use -NoNewWindow and -Credential parameters together

You can use the below code for PowerShell v2:

$user = "{user}"
$pass = ConvertTo-SecureString -String "{password}" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential `
     -argumentlist $user, $pass

start-process -Credential $cred -NoNewWindow powershell "-command & '{path and script}'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.