Search the Community
Showing results for tags 'Powershell OSD'.
-
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
-
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