Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:13:17+00:00 2026-06-09T05:13:17+00:00

I was wondering if anyone knew a way to set a default value for

  • 0

I was wondering if anyone knew a way to set a default value for a combo box in power shell? I want it to display the 1st object in the array $OperatingSystemArray I have setup when it loads.

Here is my code

$global:ComputerList = Get-Content c:\HostList.txt

# This holds the choices fro the Drop Down Menu

[array]$OperatingSystemArray = "-------------","Windows XP", "Windows 7"

# This function will grab a list of computers to work with from a .txt file

function Get-ComputerList {
    Write-Output "   List of Computers VMRest is going to be applied to:`n"
    Foreach ($Computer in $global:ComputerList) {
        Write-Output "     $Computer"
    }
    Write-Output "`n--------------------------------------------------------`n"
}

# This function will return the results of the $OperatingSystemArray and the execute commands based on the selection

function Get-OperatingSystems {

$Choice = $OSChoice.SelectedItem.ToString()

# Call correct function to run correct code

if ($Choice -match 'XP') {
    Write-Output "$Choice Base Machines selected"
    OS-WindowsXp
}
elseif ($Choice -match '7') {
    Write-Output "$Choice Base Machines selected"
    OS-Windows7
}
else {
    Write-Output "No valid Operating System Seleted"
 }
}

# This function will be called for the base machines that are running Windows XP

function OS-WindowsXp {
    Foreach ($Computer in $global:ComputerList) {
        Write-Output "Starting VMReset on $Computer"
    }
}

# This function will be called for the base machines that are running Windows 7

function OS-Windows7 {
    Foreach ($Computer in $global:ComputerList) {
       Write-Output "Starting VMReset on $Computer"
   }
}

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
[void][System.Windows.Forms.Application]::EnableVisualStyles()
[void][System.Windows.Forms.ComboBoxStyle]::DropDown

# This creates a new form

$Main = New-Object System.Windows.Forms.Form

# This sets the form options

$Main.minimumSize = New-Object System.Drawing.Size(800,600)
$Main.maximumSize = New-Object System.Drawing.Size(800,600)
$Main.Text = "VMWare Reset"
$Main.StartPosition = "CenterScreen"
$Main.ShowInTaskbar = $False


# This sets the drop down options

$OSChoice = New-Object System.Windows.Forms.ComboBox
$OSChoice.Location = New-Object System.Drawing.Size(400,10)
$OSChoice.Font = New-Object System.Drawing.Font("Courier New",16,0,3,0)
$OSChoice.Size = New-Object System.Drawing.Size(200,30)
$OSChoice.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList

# This For-Loop populates the $OSChoice items from $OperatingSystemArray

ForEach ($Item in $OperatingSystemArray) {
  $OSChoice.Items.Add($Item)
}

# This adds the $OSChoice Item to the gui

$Main.Controls.Add($OSChoice)

# This sets the $OSChoice label options

$OSChoiceLabel = New-Object System.Windows.Forms.Label
$OSChoiceLabel.Location = New-Object System.Drawing.Size(10,10)
$OSChoiceLabel.Font = New-Object System.Drawing.Font("Courier New",16,0,3,0)
$OSChoiceLabel.Size = New-Object System.Drawing.Size(300,30)
$OSChoiceLabel.Text = "Base Machine Operating System"

# This adds the $OSChoiceLabel Item to the gui

$Main.Controls.Add($OSChoiceLabel)

# This sets up the button options
$ExecuteButton = New-Object System.Windows.Forms.Button
$ExecuteButton.Location = New-Object System.Drawing.Size(650,10)
$ExecuteButton.Size = New-Object System.Drawing.Size(100,30)
$ExecuteButton.Text = "Execute Reset"
$ExecuteButton.Add_Click( {

    Get-OperatingSystems

    if ($SaveToCheckBox.Checked -eq $True) {
        Write-Output "Saving output to file"
    }
    else {
        Write-Output "Not saving output to file"
    }
})

# This adds the $ExecuteButton Item to the gui

$Main.Controls.Add($ExecuteButton)

# This sets up the $CloseButton Item to the gui



# This sets up the output window for the gui

$OutputBox = New-Object System.Windows.Forms.RichTextBox
$OutputBox.Text = ''
$OutputBox.Name = 'OutputBox'
$OutputBox.Font = New-Object System.Drawing.Font("Courier New",16,0,3,0)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 760
$System_Drawing_Size.Height = 460
$OutputBox.Size = $System_Drawing_Size
$OutputBox.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 50
$OutputBox.Location = $System_Drawing_Point

# This adds the Output box to the GUI

$Main.Controls.Add($OutputBox)

# This adds a checkbox to the GUI

$SaveToCheckBox = New-Object System.Windows.Forms.CheckBox
$SaveToCheckBox.Text = 'Save to File?'
$SaveToCheckBox.Name = 'SaveToCheckBox'
$SaveToCheckbox.Font = New-Object System.Drawing.Font("Courier New",16,0,3,0)
$SaveToCheckBox.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 200
$System_Drawing_Size.Height = 30
$SaveToCheckBox.Size = $System_Drawing_Size
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 550
$System_Drawing_Point.Y = 530
$SaveToCheckBox.Location = $System_Drawing_Point

# Default is set to false if you want to log the output to a file set to $True

$SaveToCheckBox.Checked = $Flase

$Main.Controls.Add($SaveToCheckBox)

Get-ComputerList

# This function displays the output to a text box within the gui

function Write-Output {
    param([string]$msg)
    $OutputBox.Text += "$msg`n"
    $OutputBox.SelectionStart = $OutputBox.Text.Length - 1;
    $OutputBox.ScrollToCaret();
}

# This activates and shows the gui
$Main.Add_Shown({
$Main.Activate()
})
[void]$Main.ShowDialog() | Out-Null
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:13:19+00:00Added an answer on June 9, 2026 at 5:13 am

    Did you try setting the SelectedItem property of the $OSChoice control to the default value?

    Here’s the snippet of code I was looking at. It’s pretty general but it is doing what you ask:

     function set-controlvalue{
     param($control,
           $value)
           switch ($control.GetType().Name) {
            'TextBox' {
               $control.Text=$value 
            }
            'ComboBox' {
              $control.SelectedItem=$value 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone knew of way of making gvim to default to
I was wondering if anyone knew of a way to do some client side
I was wondering if anyone knew a good way of creating an AS3 Facebook
I was wondering if anyone knew of a way to mimic the .show(); method
I was wondering if anyone knew a better way to write this block of
Hay I was wondering if anyone knew a better way to do this. def
I was wondering if anyone knew of a simple way to implement graphing in
I was wondering if anyone knew a good way to convert a multi-page PDF
I was wondering if anyone knew the best way of getting in a UITableView,
I was wondering whether anyone knew of a way to attach an event/callback to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.