P. Grunder P. Grunder - 1 year ago 104
PowerShell Question

Executing different .cmd Files inside Powershell Script

Im trying to execute a .cmd file inside of my Powershell Script. How can i implement that?

Each Checkbox (if checked) should execute another .cmd file.

Here's the Powershell Code i got so far. (instead of the command i just checked if the chexboxes are even selected):

#Checkbox Events

if ($checkBox1.Checked) { $listBox1.Items.Add( "Checkbox 1 is checked" ) }
if ($checkBox2.Checked) { $listBox1.Items.Add( "Checkbox 2 is checked" ) }
if ($checkBox3.Checked) { $listBox1.Items.Add( "Checkbox 3 is checked" ) }
if ($checkBox4.Checked) { $listBox1.Items.Add( "Checkbox 4 is checked" ) }
if ($checkBox5.Checked) { $listBox1.Items.Add( "Checkbox 5 is checked" ) }
if ($checkBox6.Checked) { $listBox1.Items.Add( "Checkbox 6 is checked" ) }

if ( !$checkBox1.Checked -and !$checkBox2.Checked -and !$checkBox3.Checked -and !$checkBox4.Checked -and !$checkBox5.Checked -and !$checkBox6.Checked) { $listBox1.Items.Add("No CheckBox selected....")}

Answer Source

Call it the cmd file:

& C:\Path\To\cmd.cmd

Since you only fill listBox1 when you have a checked box, you can significantly simplify the last test.

if ($listBox1.Items.Count -eq 0) {
    $listBox1.Items.Add("No CheckBox selected....")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download