Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell Script Dropdown List Passes Argument to Expiration Date

$
0
0

Hello,

I am trying to configure this script so that the user has a choice to make.  If the user chooses "FTE", then the script proceeds to the next function.  If the user chooses "Contractor", he is then taken to the expiration date portion of the script.  How do I configure this script to flow in that manner?

# Edit This item to change the DropDown Values
[array]$DropDownArray = "FTE", "Contractor"

# This Function Returns the Selected Value and Closes the Form

function Return-DropDown {

$Choice = $DropDown.SelectedItem.ToString()
$Form.Close()
#Write-Host $Choice
 $MyChoice = $Choice
 #Write-Host $MyChoice
 $Script:Choice = $DropDown.SelectedItem.ToString()
 $Form.Close()
}

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") |Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") |Out-Null

$Form = New-Object System.Windows.Forms.Form
$Form.width = 300
$Form.height = 150
$Form.Text = ”User Type”

$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown.Location = new-object System.Drawing.Size(100,10)
$DropDown.Size = new-object System.Drawing.Size(130,30)
$DropDown.DropDownStyle = "DropDownList" # This style of combobox will prevent blank
# item selection.

ForEach ($Item in $DropDownArray) {
$DropDown.Items.Add($Item) | Out-Null # Added pipe to out-null to prevent index from
# showing up in the console window.
}

$DropDown.SelectedIndex = 0 # Select the first item by default

$Form.Controls.Add($DropDown)

$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(10,10)
$DropDownLabel.size = new-object System.Drawing.Size(100,20)
$DropDownLabel.Text = "Items"
$Form.Controls.Add($DropDownLabel)

$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(100,50)
$Button.Size = new-object System.Drawing.Size(100,20)
$Button.Text = "Select an Item"
$Button.Add_Click({Return-DropDown})
$form.Controls.Add($Button)

$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog() | Out-Null # out-null to prevent "OK" or "Cancel"
# from appearing in the console window

#Set the expiration date
$ans=Read-Host 'What is the expiration date of this account? (mm-dd-yyyy)'
$expDate=[datetime]$ans

HELP Read-Host -Full

##End of Script

Thanks in advance for your help.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>