Task sequence UI import from ini file

  • Task sequence UI import from ini file

    Posted by Roddy Gelberty on 9 July 2020 at 4:33 pm

    I saw your Technet repository for User input Task sequence https://gallery.technet.microsoft.com/scriptcenter/SCCM-2012-OSD-Task-9c3f2be7#content

    I have been struggling with trying to create a MDT wizard Menu User Input Task sequence which prompts with forms and drag down for Field Tech to input information like IP address, Street name POS store information (which are part of INI files) will be available at the time of installation.

    I have three .ini files , Form on OSD Menu UI has to be populated with contents in the 3 .ini files and save the entered data to C:\ . once the data is entered it can boot to applying image.

    Can you please advise with any solution?

    This question was posted by @Rocky .

    Roddy Gelberty replied 3 years, 9 months ago 3 Members · 9 Replies
  • 9 Replies
  • Roddy Gelberty

    Member
    9 July 2020 at 8:11 pm

    Varun, can you please confirm which one of the following statements are true?

    • You use a standalone MDT infrastructure and not SCCM.
    • You use an SCCM infrastructure.

    Can you also clarify what you mean, when you say ‘save the entered data to C:‘. Do you mean the selected choice?. If yes? in what format?
    Do you have to use ‘.ini’ as a the input source?

    • Roddy Gelberty

      Member
      10 July 2020 at 1:53 am

      Hi Bobby,
      Yes I am using a standalone MDT infrastructure and not SCCM.
      Once the user inputs the data into Wizard, if it can save the data to the ini file and have it saved it C:\Directory after applying the image, or if there is any other way to do it.

  • Topaz George

    Organizer
    9 July 2020 at 10:43 pm

    @Rocky . Furter to Bobby’s questions, can you also clarify what you mean by ‘will be available at the time of installation‘ Will you be adding conditions to your Task Sequence steps using the values you collect from the UI (User Interface)?

    • Roddy Gelberty

      Member
      10 July 2020 at 1:59 am

      Sure Paul,
      Please find the fields example from one of the INI file, the information which goes in
      to these ini files like Store Address, IP address these information is
      only available to enter by field technician at the time of Deployment.
      [General]store_number =00000address =city =Some CityCountry =USProvince =N/Acontact =Store Managertype =Cpetrol =0timezone =GMTdaylight =1remarks =cc_connect_type =4credit =1market =0000

      Three .ini files have fields like above, the information which goes in to these ini files like Store Address, IP address these information is only available to enter by field technician at the time of Deployment, once these .ini files are saved with updated information to C:\Store directory on 2016 hyper-v server, we have power shell scripts in place which will inject these .ini files to VM.

  • Roddy Gelberty

    Member
    10 July 2020 at 9:49 am

    Thanks Varun. For SCCM users we always recommend our Free SCCM task sequence orchestrator which has 18 extension attributes that can be assigned entries that originally go into the INI file. But since you use MDT, the process from the start to finish has to be done using PowerShell, leveraging the power of ‘Windows Forms’ or ‘Windows Presentation Foundation’.

    Step 1: Create a Form with all the required fields. See a very short example below.

    Add-Type -AssemblyName System.Windows.Forms
    [System.Windows.Forms.Application]::EnableVisualStyles()
    $storeInfo = New-Object system.Windows.Forms.Form
    $storeInfo.ClientSize = New-Object System.Drawing.Point(594,113)
    $storeInfo.text = "Store Information Window"
    $storeInfo.TopMost = $false
    $storeInfo.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#ffffff")
    $storeAddress = New-Object system.Windows.Forms.Label
    $storeAddress.text = "Store Address : "
    $storeAddress.AutoSize = $false
    $storeAddress.width = 91
    $storeAddress.height = 6
    $storeAddress.location = New-Object System.Drawing.Point(10,68)
    $storeAddress.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
    $IPAddress = New-Object system.Windows.Forms.Label
    $IPAddress.text = "IP Address : "
    $IPAddress.AutoSize = $false
    $IPAddress.width = 108
    $IPAddress.height = 5
    $IPAddress.location = New-Object System.Drawing.Point(10,20)
    $IPAddress.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
    $TextBox1 = New-Object system.Windows.Forms.TextBox
    $TextBox1.multiline = $false
    $TextBox1.width = 430
    $TextBox1.height = 20
    $TextBox1.location = New-Object System.Drawing.Point(145,15)
    $TextBox1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
    $TextBox2 = New-Object system.Windows.Forms.TextBox
    $TextBox2.multiline = $false
    $TextBox2.width = 430
    $TextBox2.height = 20
    $TextBox2.location = New-Object System.Drawing.Point(145,61)
    $TextBox2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
    $storeInfo.controls.AddRange(@($storeAddress,$IPAddress,$TextBox1,$TextBox2))

    Add extra fields like text boxes and combo boxes to suite your needs. This article can guide you in the right direction.

    Step 2: Read your INI files and pre-populate necessary fields.

    function Get-IniContent ($filePath)
    {
        $ini = @{}
        switch -regex -file $FilePath
        {
            "^\[(.+)\]" # Section
            {
                $section = $matches[1]
                $ini[$section] = @{}
                $CommentCount = 0
            }
            "^(;.*)$" # Comment
            {
                $value = $matches[1]
                $CommentCount = $CommentCount + 1
                $name = "Comment" + $CommentCount
                $ini[$section][$name] = $value
            }
            "(.+?)\s*=(.*)" # Key
            {
                $name,$value = $matches[1..2]
                $ini[$section][$name] = $value
            }
        }
        return $ini
    }

    The above script was taken from Microsoft dev blog.

    Step 3 : Read the values from the ‘PowerShell’ Form and write it to the INI file on your SYSTEM drive.

    function Out-IniFile($InputObject, $FilePath)
    {
        $outFile = New-Item -ItemType file -Path $Filepath
        foreach ($i in $InputObject.keys)
        {
            if (!($($InputObject[$i].GetType().Name) -eq "Hashtable"))
            {
                #No Sections
                Add-Content -Path $outFile -Value "$i=$($InputObject[$i])"
            } else {
                #Sections
                Add-Content -Path $outFile -Value "[$i]"
                Foreach ($j in ($InputObject[$i].keys | Sort-Object))
                {
                    if ($j -match "^Comment[\d]+") {
                        Add-Content -Path $outFile -Value "$($InputObject[$i][$j])"
                    } else {
                        Add-Content -Path $outFile -Value "$j=$($InputObject[$i][$j])"
                    }
    
                }
                Add-Content -Path $outFile -Value ""
            }
        }
    }

    The above script was taken from Microsoft dev blog.

    If you run the PowerShell Form during the execution of the task sequence, remember to do the following.

    $TSProgressUI = new-object -comobject Microsoft.SMS.TSProgressUI
    $TSProgressUI.CloseProgressDialog()
    $TSProgressUI = $null

    The above commands turn off the progress UI.

    Hope this helps.

    • Roddy Gelberty

      Member
      10 July 2020 at 6:33 pm

      Thank you Bobby!
      I appreciate it. I will check it out.

      • Roddy Gelberty

        Member
        10 July 2020 at 6:56 pm

        @bobby-brown
        Bobby,
        Quick question, Do i have to treat step 1, step 2, step 3 as separate powershell scripts?
        for instance, form in step 1 goes as form.ps1, then read ini files and pre-populate as readini.ps1
        and write form to the ini file as WriteFormtoINI.ps1, and set them as run powershell scripts in the task sequence?

        Thank you!

  • Roddy Gelberty

    Member
    10 July 2020 at 8:05 pm

    You could put it all in one script.
    In short,

    • Pre-populate necessary fields from INI.
    • Operator fills in additional details.
    • Write back to the same INI or different INI (depending on your needs).

    Hope that helps.

Log in to reply.

DCOM hardening issue.

This application fails to authenticate with WMI on the SCCM server because Microsoft has not yet hardened DCOM on their Windows Preinstallation Environment. We are working on a different approach, but it will only be released during the first quarter of 2024. But until that time, the only workaround will be to uninstall the update corresponding to KB5004442.