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?
Thanks,
Ben
This should be what you need:
You can use the Start-Process cmdlet (PowerShell 2.0):
Start-Process cmd.exe -Credential $credential -WindowStyle Hidden -WorkingDirectory ... -ArgumentList...
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: