I currently open my PowerShell script through a .bat file. The script has a GUI. I tried to put this in my script but it hid the GUI as well and also kept looping because I
If you run PowerShell from a shortcut with the window set to minimized, it will briefly flash a cmd icon in the taskbar but you barely notice it. Yet, it will start your PowerShell GUI without having a console window behind it.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle Hidden -file "C:\path\whatever.ps1"
If you want to start a second GUI console window from whatever.ps1 without it stopping the processing on whatever.ps1 you need to use start-process. However, start-process with -WindowStyle hidden prevents the GUI from showing up. Removing -WindowStyle shows a command window behind your GUI. However, if you start-process with cmd.exe /k, it does work.
$argumentlist = "/c powershell.exe -file `"c:\path\whatever2.ps1`" -param1 `"paramstring`""
Start-Process cmd.exe -WindowStyle Hidden -ArgumentList $argumentlist
As a bonus, if you start whatever2.ps1 with a param() statement, you can pass named, required arguments. Just be sure it's the very first thing in the ps1 file, before assemblies even.
param (
[Parameter(Mandatory=$true)]
[string]$var1
)
$argumentlist = "/c powershell.exe -file `"C:\path\whatever2.ps1`" -param1 `"param1string`""