Jump to content


  • 0
gbrown135

Script Radio Button Powershell in OSD

Question

I am working for a company who is looking to create a new Windows 10 image. I have a powershell script that prompts for a Computer name and this all works fine by passing the OSDComputerName variable to the TS.

I'm trying to introduce is another powershell script that will ask the user to select one of 2 domains. This is done by selecting one of 2 radio buttons in a Powershell Form called by a function. Whichever one is selected will create a custom TS variable and the variable will be passed on later to the Task Sequence and the correct Network Settings will be set dependent on which domain is selected. The problem is the Domain Select script doesn't seem to run as part of the TS and it just sits there. The code of the script is shown below

--------------------------------------------------------------------------------------------------------------------------------------------

#Disable Task Sequence Progress Screen

$tsui = New-Object -COMObject Microsoft.SMS.TSProgressUI
$tsui.closeprogressdialog()
# A function to create the form
function Domain_Form{
[void] [system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [system.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
# Set the size of your form
$Form = New-Object System.Windows.Forms.Form
$Form.width = 500
$Form.height = 300
$Form.Text = ”Please select domain"
# Set the font of the text to be used within the form
$Font = New-Object System.Drawing.Font("Times New Roman",12)
$Form.Font = $Font
# Create a group that will contain your radio buttons
$MyGroupBox = New-Object System.Windows.Forms.GroupBox
$MyGroupBox.Location = '40,30'
$MyGroupBox.size = '400,150'
$MyGroupBox.text = "Select PRIMARY or SECONDARY Domain"
# Create the collection of radio buttons
$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = '20,40'
$RadioButton1.size = '350,20'
$RadioButton1.Checked = $true
$RadioButton1.Text = "PRIMARY"
$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = '20,70'
$RadioButton2.size = '350,20'
$RadioButton2.Checked = $false
$RadioButton2.Text = "SECONDARY"
#$RadioButton3 = New-Object System.Windows.Forms.RadioButton
#$RadioButton3.Location = '20,100'
#$RadioButton3.size = '350,20'
#$RadioButton3.Checked = $false
#$RadioButton3.Text = "??"
# Add an OK button
# Thanks to J.Vierra for simplifing the use of buttons in forms
$OKButton = new-object System.Windows.Forms.Button
$OKButton.Location = '130,200'
$OKButton.Size = '100,40'
$OKButton.Text = 'OK'
$OKButton.DialogResult=[system.Windows.Forms.DialogResult]::OK
#Add a cancel button
$CancelButton = new-object System.Windows.Forms.Button
$CancelButton.Location = '255,200'
$CancelButton.Size = '100,40'
$CancelButton.Text = "Cancel"
$CancelButton.DialogResult=[system.Windows.Forms.DialogResult]::Cancel
# Add all the Form controls on one line
$form.Controls.AddRange(@($MyGroupBox,$OKButton,$CancelButton))
# Add all the GroupBox controls on one line
$MyGroupBox.Controls.AddRange(@($Radiobutton1,$RadioButton2,$RadioButton3))
# Assign the Accept and Cancel options in the form to the corresponding buttons
$form.AcceptButton = $OKButton
$form.CancelButton = $CancelButton
# Activate the form
$form.Add_Shown({$form.Activate()})
# Get the results from the button click
$dialogResult = $form.ShowDialog()
# If the OK button is selected
if ($dialogResult -eq "OK"){
# Check the current state of each radio button and respond accordingly
if ($RadioButton1.Checked){
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$tsenv.Value("CustomDomain") = "PRIMARY"}
elseif ($RadioButton2.Checked){
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$tsenv.Value("CustomDomain") = "SECONDARY"}
}
}
# Call the function
Domain_Form
--------------------------------------------------------------------------------------------------------------------------------------------
The task sequence progress bar disappears when it's run but thats about it and nothing else ever comes back up.
The strange thing is if I run the script in a command prompt manually it runs OK
Any help would be appreciated

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

are you running this in Windows ? if so the task sequence engine runs as the system account so you cannot see what it pops up, you need to use serviceUI.exe from the MDT toolkit to pop up your powershell gui

 

this post will give you the ideas needed to get it to work

Share this post


Link to post
Share on other sites

  • 0

are you running this in Windows ? if so the task sequence engine runs as the system account so you cannot see what it pops up, you need to use serviceUI.exe from the MDT toolkit to pop up your powershell gui

 

this post will give you the ideas needed to get it to work

Hi

 

No I'm running this in the TS Environment before a the OS Setup takes place, does this still apply at this stage of the TS?

Share this post


Link to post
Share on other sites

  • 0

I have similar scripts and I encountered a similar behavior recently. In my case, it turned out that I was executing the powershell script with the "Run PowerShell script" task, as I saw you are doing. The solution is to run this as a "Run Command Line" task. The explanation could be this: When you run the PowerShell native task, the script is executed in the same process as the Task Sequence, and when it closes the Task Sequence GUI, it closes also it's own GUI, hanging itself... :) When you run this with the Command Line task, it opens a new powershell process, that closes and resumes the Task Sequence GUI.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.