none
MDT 2012 and Interactive Scripts

    Question

  • So I have seen a few posts online about this and since most posts are either unanswered or very unclear I figured that I would ask.

    I have a Windows 7 64-bit deployment configured on the server.  Under the State Restore I have some custom tasks (scripts) running.  

    The first of these items is a Run Command Line option with the following info so that I can run my scripts (I also have one at the end that sets things back to restricted):  powershell -noprofile -command "Set-ExecutionPolicy Unrestricted LocalMachine"

    I have 2 powershell scripts that I am running in between to accomplish my task.  The first is a powershell script that presents a form with radial buttons and allows a user to select the appropriate choice so that the system can modify the registry accordingly.  The second just verifies that a change has been made and will tell users if it did or didn't work.  both scripts are verified working when I run them standalone on a system.  My issue is as follows:  when I have them both enabled it sits and waits for the first script but nothing happens.  When I disable the first script and just run the second script that script works fine.  From what I can tell the script should work since they are both forms but am I missing something?  The code to the scripts is below:

    1st script ():

    ########
    ##Initialization Section
    ########

    $RegPath = "string"        #Stores the Registry Hive Location

    #Load Necessary Pieces
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  

    $Form = New-Object System.Windows.Forms.Form    
    $Form.Size = New-Object System.Drawing.Size(600,400)  

    ########
    ##Function Section
    ########

    function buttonInfo {

    if ($RadioButton1.Checked -eq $true) {
         Set-ItemProperty -Path $RegPath -Name 'Domain' -Value "dept1.company.com"
         Set-ItemProperty -Path $RegPath -Name 'NV Domain' -Value "dept1.company.com"
         [environment]::exit(0)
         #[System.Windows.Forms.Application]::Exit($null)
        
    }
    if ($RadioButton2.Checked -eq $true) {
         Set-ItemProperty -Path $RegPath -Name 'Domain' -Value "dept2.company.com"
         Set-ItemProperty -Path $RegPath -Name 'NV Domain' -Value "dept2.company.com"
         [environment]::exit(0)
         #[System.Windows.Forms.Application]::Exit($null)
        
    }
    if ($RadioButton3.Checked -eq $true) {
         Set-ItemProperty -Path $RegPath -Name 'Domain' -Value "dept3.company.com"
         Set-ItemProperty -Path $RegPath -Name 'NV Domain' -Value "dept3.company.com"
         [environment]::exit(0)
         #[System.Windows.Forms.Application]::Exit($null)
        
    }
    if ($RadioButton4.Checked -eq $true) {
         Set-ItemProperty -Path $RegPath -Name 'Domain' -Value "dept4.company.com"
         Set-ItemProperty -Path $RegPath -Name 'NV Domain' -Value "dept4.company.com"
         [environment]::exit(0)
         #[System.Windows.Forms.Application]::Exit($null)
        
    }
    if ($RadioButton5.Checked -eq $true) {
         Set-ItemProperty -Path $RegPath -Name 'Domain' -Value "dept5.company.com"
         Set-ItemProperty -Path $RegPath -Name 'NV Domain' -Value "dept5.company.com"
         [environment]::exit(0)
         #[System.Windows.Forms.Application]::Exit($null)
        
    }
    if ($RadioButton6.Checked -eq $true) {
         Set-ItemProperty -Path $RegPath -Name 'Domain' -Value "dept6.company.com"
         Set-ItemProperty -Path $RegPath -Name 'NV Domain' -Value "dept6.company.com"
         [environment]::exit(0)
         #[System.Windows.Forms.Application]::Exit($null)
        
    }
    if ($RadioButton7.Checked -eq $true) {
         Set-ItemProperty -Path $RegPath -Name 'Domain' -Value "dept7.company.com"
         Set-ItemProperty -Path $RegPath -Name 'NV Domain' -Value "dept7.company.com"
         [environment]::exit(0)
         #[System.Windows.Forms.Application]::Exit($null)
        
    }
    if ($RadioButton8.Checked -eq $true) {
         Set-ItemProperty -Path $RegPath -Name 'Domain' -Value "dept8.company.com"
         Set-ItemProperty -Path $RegPath -Name 'NV Domain' -Value "dept8.company.com"
         [environment]::exit(0)
         #[System.Windows.Forms.Application]::Exit($null)
        
    }

    } #end buttonInfo Function


    ########
    ##Main Processing Section
    ########

    #Assign a variable for the needed registry section and set that as the location
    $RegPath =  'hklm:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters'
    Set-Location $RegPath

    #Change the DWORD registry value
    Set-ItemProperty -Path $RegPath -Name SyncDomainWithMembership -Type DWORD -Value 0x00000000


    # Create Form Window
    $form = New-Object Windows.Forms.Form
    $form.text = "DNS Suffix List"
    $form.top = 10
    $form.left = 10
    $form.height = 275   #Height of overall window
    $form.width = 255

    # Create Form Label
    $label = New-Object System.Windows.Forms.Label
    $label.text = "  Select the appropriate computer DNS suffix:"
    $label.height = 15
    $label.width = 250
    $label.top = 10     #Spacing from top
    $label.left = 5
    $form.controls.add($label)

    # Create Department 1 radio button
    $RadioButton1 = New-Object System.Windows.Forms.radiobutton
    $RadioButton1.text = "  Department 1"
    $RadioButton1.height = 20
    $RadioButton1.width = 150
    $RadioButton1.top = 35     #Spacing from top
    $RadioButton1.left = 85
    $form.controls.add($RadioButton1)

    # Create Department 2 radio button
    $RadioButton2 = New-Object System.Windows.Forms.radiobutton
    $RadioButton2.text = "  Department 2"
    $RadioButton2.height = 20
    $RadioButton2.width = 150
    $RadioButton2.top = 55     #Spacing from top
    $RadioButton2.left = 85
    $form.controls.add($RadioButton2)

    # Create Department 3 radio button
    $RadioButton3 = New-Object System.Windows.Forms.radiobutton
    $RadioButton3.text = "  Department 3"
    $RadioButton3.height = 20
    $RadioButton3.width = 150
    $RadioButton3.top = 75     #Spacing from top
    $RadioButton3.left = 85
    $form.controls.add($RadioButton3)

    # Create Department 4 radio button
    $RadioButton4 = New-Object System.Windows.Forms.radiobutton
    $RadioButton4.text = "  Department 4"
    $RadioButton4.height = 20
    $RadioButton4.width = 150
    $RadioButton4.top = 95     #Spacing from top
    $RadioButton4.left = 85
    $form.controls.add($RadioButton4)

    # Create Department 5 radio button
    $RadioButton5 = New-Object System.Windows.Forms.radiobutton
    $RadioButton5.text = "  Department 5"
    $RadioButton5.height = 20
    $RadioButton5.width = 150
    $RadioButton5.top = 115     #Spacing from top
    $RadioButton5.left = 85
    $form.controls.add($RadioButton5)

    # Create Department 6 radio button
    $RadioButton6 = New-Object System.Windows.Forms.radiobutton
    $RadioButton6.text = "  Department 6"
    $RadioButton6.height = 20
    $RadioButton6.width = 150
    $RadioButton6.top = 135     #Spacing from top
    $RadioButton6.left = 85
    $form.controls.add($RadioButton6)

    # Create Department 7 radio button
    $RadioButton7 = New-Object System.Windows.Forms.radiobutton
    $RadioButton7.text = "  Department 7"
    $RadioButton7.height = 20
    $RadioButton7.width = 150
    $RadioButton7.top = 155     #Spacing from top
    $RadioButton7.left = 85
    $form.controls.add($RadioButton7)

    # Create Department 8 radio button
    $RadioButton8 = New-Object System.Windows.Forms.radiobutton
    $RadioButton8.text = "  Department 8"
    $RadioButton8.height = 20
    $RadioButton8.width = 150
    $RadioButton8.top = 175     #Spacing from top
    $RadioButton8.left = 85
    $form.controls.add($RadioButton8)


    # Form Confirmation Button
    $button = New-Object System.Windows.Forms.Button
    $button.text = "Confirm"
    $button.height = 20
    $button.width = 70
    $button.top = 205     #Spacing from top
    $button.left = 85
    $button.Add_Click({buttonInfo})     #Accessing button behavior function
    $form.controls.add($button)

    # Activate Form
    $Form.Add_Shown({$Form.Activate()})
    [void] $Form.ShowDialog() 

    2nd script:

    ########
    ##Initialization Section
    ########

    $RegPath = "string"        #Stores the Registry Hive Location

    #Load Necessary Pieces
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  

    $Form = New-Object System.Windows.Forms.Form    
    $Form.Size = New-Object System.Drawing.Size(650,450)  



    ########
    ##Main Processing Section
    ########

    #Assign a variable for the needed registry section and set that as the location
    $RegPath =  'hklm:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters'
    Set-Location $RegPath

    #Store registry values
    $SValue = $(Get-ItemProperty $RegPath).SyncDomainWithMembership
    $DValue = $(Get-ItemProperty $RegPath).Domain
    $NValue = $(Get-ItemProperty $RegPath).'NV Domain'

    if (($SValue -eq 0) -and ($DValue -ne $null) -and ($NValue -ne $null) -and ($DValue -match $DValue)) {
         [System.Windows.Forms.MessageBox]::Show("        Sync Domain Membership has been properly disabled!" + "`n`n`t`t" + 
           "             AND" + "`n`n" + "        DNS Suffix has been set to:  `t" + $DValue, "Status" , 0)
    }
    else {
         [System.Windows.Forms.MessageBox]::Show("An unknown error has occurred! - " + "`n`n" + 
           "Please set the system FQDN manually." , "Error" , 0)   
    }

    Now I will apologize for my code as I haven't done PowerShell and scripting in some time and this was more of a get done quickly as long as it works properly (will clean up later then).  I need to take user input and do things this way with these particular changes.   I know some users mention configuring as an application but I have to believe that this can be done also.  Any help would be appreciated.

    Friday, March 29, 2013 8:03 PM

Answers

All replies

  •  

    The first of these items is a Run Command Line option with the following info so that I can run my scripts (I also have one at the end that sets things back to restricted):  powershell -noprofile -command "Set-ExecutionPolicy Unrestricted LocalMachine"

    Just a quick pointer first. There's no need to alter the execution policy. Just use the "Run Powershell script" Task sequence step and it will take care of this for you.

    Blog: http://scriptimus.wordpress.com

    Sunday, March 31, 2013 5:34 PM
  • After looking at all the forums and posts I am under the impression that you cannot use interactive PowerShell or VBS scripts during the deployment.  My tests have shown that message boxes and such work but it will never display if I try to use forms or anything similar.

    I decided to shift the focus and convert the VB version of the script that I have into AutoIt to provide me the same functionality as in PowerShell.  My new issue is as follows - how do I get the exe to run?  I know and have seen information on using source files and such but just struggling to get the information I need to run this type of file (especially difficult as there will be no command line parameters).

    Tuesday, April 02, 2013 3:54 PM
  • If it's an exe (now), why not import and run as an Application and just add to your Task Sequence as an Application step?

    David Coulter | http://DCtheGeek.blogspot.com | @DCtheGeek

    Tuesday, April 02, 2013 4:01 PM
    Answerer
  • You could also consider crafting custom Forms to obtain the info you are looking for prior to deployment.
    Tuesday, April 02, 2013 4:39 PM
  • The custom form for prior to deployment was something that won't work based on what I need.  As for the EXE I am running into issues with how to import so a quick generic walkthrough could help.
    Tuesday, April 02, 2013 6:14 PM
  • There are several good articles and blogs out there for using MDT.  Here's a few specific ones for using an Application:

    Once you pull it in as an Application, you'll add it to your Task Sequence as a Step (General --> Install Application), change to "Install a single application" and browse to the one you've imported.


    David Coulter | http://DCtheGeek.blogspot.com | @DCtheGeek

    • Marked as answer by Jonny_K Wednesday, April 03, 2013 2:21 PM
    Tuesday, April 02, 2013 6:23 PM
    Answerer
  • That was exactly what I need - thanks!  I got all the way through the Application Import before but got stuck on the command details page not realizing that all I had to put in there was the name of the exe and nothing else to make it work properly.
    Wednesday, April 03, 2013 2:22 PM