Powershell form will not open from batch file using -windowstyle Hidden parameter

Hi All,
I have a simple powershell form that is working fine and I am opening that from a batch file and this is also working. My batch file is like this:

@echo off
PowerShell.exe -executionpolicy bypass -Command “start-process ‘powershell.exe’ '-Command “”.\test.ps1”’ -WindowStyle Hidden -credential “org\itd412” -passthru"

it works fine without the -WindowStyle Hidden parameter but as soon as I use this parameter it does not open the form. The problem is that without the parameter it open a powershell console window in the back ground of the form. I am going crazy with this. Below is my form code:

Add-Type -AssemblyName System.Windows.Forms

Create form

$form = New-Object System.Windows.Forms.Form
$form.Text = “My Form”
$form.Size = New-Object System.Drawing.Size(600,500)
$form.StartPosition = “CenterScreen”

Create label and textbox for computer name input

$lblComputerName = New-Object System.Windows.Forms.Label
$lblComputerName.Location = New-Object System.Drawing.Point(10,10)
$lblComputerName.Text = “Computer Name:”

$txtComputerName = New-Object System.Windows.Forms.TextBox
$txtComputerName.Location = New-Object System.Drawing.Point(120,10)
$txtComputerName.Size = New-Object System.Drawing.Size(150,20)

Create connect button

$btnConnect = New-Object System.Windows.Forms.Button
$btnConnect.Location = New-Object System.Drawing.Point(10,50)
$btnConnect.Text = “Connect”

Create disconnect button

$btnDisconnect = New-Object System.Windows.Forms.Button
$btnDisconnect.Location = New-Object System.Drawing.Point(90,50)
$btnDisconnect.Text = “Disconnect”

Create display panel (RichTextBox)

$displayPanel = New-Object System.Windows.Forms.RichTextBox
$displayPanel.Location = New-Object System.Drawing.Point(10,210)
$displayPanel.Size = New-Object System.Drawing.Size(580,500)
$displayPanel.ScrollBars = “Both”
$displayPanel.WordWrap = $false
$displayPanel.Font = New-Object System.Drawing.Font(“Lucida Console”, 9)

Show the form

$form.ShowDialog() | Out-Null

Please go back, edit your question and fix teh formatting of you code.

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

How about using -Minimized instead of -Hidden?

Hidden is intended for silent running code. Everything produced by that window will be hidden including a dotNET form.