Loading POwershell Issues (Post SCCM Deployment Boot Strapper)

I was wondering if any of you super tallanted scripters can help or atleast offer advise as to why this is not working.

So i have a Powershell script that collects data from the Registry and shows the output ina very simple form at the end of a SCCM deployment. (This for is WIP and i will ament it to show errors later etc… but for now this will only come up if the deployment was good with no errors)

So if i change my Script to show
$Form.WindowState = ‘Maximized’ - It works but the format is all tucked up in the top/left part of the screen. If i change it to
$Form.WindowState = ‘Normal’ or just remove the other command as Normal is default. The system just sits at the pre loading screen and does nothing at all. This is really annoying me so any help would be amazing.

After the Build it runs a boot strapper to load the Powershell Script outside of the Task Sequence


Dim oWS
Set oWS = CreateObject("Wscript.Shell")

Call oWS.Run("%windir%\system32\osdsetuphook.exe /execute", 0 , true)
Call oWS.Run("powershell.exe -ExecutionPolicy Bypass -File %windir%\Temp\OSDReport\Report.ps1", 0 , true)

Wscript.Quit(0)

~~~ Report.ps1 ~~~

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form = New-Object system.Windows.Forms.Form
$Form.text = "Build LAB"
$Form.TopMost = $True

$Form.WindowState = 'Normal'          
#$Form.WindowState = 'Maximized'        

$Form.Height = 240
$Form.Width = 350
$Form.FormBorderStyle = 'FixedDialog'
$Form.MaximizeBox = $False
$Form.MinimizeBox = $False
$Form.Name = 'Build'
$Form.StartPosition = 'CenterScreen'
$Form.FormBorderStyle = 'FixedDialog'
$Form.controls.AddRange(@($Label1,$Label2,$Label3,$Label4,$Label5,$Label6,$Label7,$Label8,$Label9,$Button1))

$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "Build Complete"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(88,14)
$Label1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',15,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
$Label1.ForeColor = "Green"

$Label2 = New-Object system.Windows.Forms.Label
$Label2.text = "Host Name"
$Label2.AutoSize = $true
$Label2.width = 25
$Label2.height = 10
$Label2.location = New-Object System.Drawing.Point(15,47)
$Label2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Label2.ForeColor = "Blue"

$Label3 = New-Object system.Windows.Forms.Label
$Label3.text = Get-ItemPropertyValue -Path HKLM:\SOFTWARE\BuildInfo\ -Name "OSDComputerName"
$Label3.AutoSize = $true
$Label3.width = 25
$Label3.height = 10
$Label3.location = New-Object System.Drawing.Point(158,47)
$Label3.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Label4 = New-Object system.Windows.Forms.Label
$Label4.text = "Deployment Date"
$Label4.AutoSize = $true
$Label4.width = 25
$Label4.height = 10
$Label4.location = New-Object System.Drawing.Point(15,77)
$Label4.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Label4.ForeColor = "Blue"

$Label5 = New-Object system.Windows.Forms.Label
$Label5.text = Get-ItemPropertyValue -Path HKLM:\SOFTWARE\BuildInfo\ -Name "DeploymentDate"
$Label5.AutoSize = $true
$Label5.width = 25
$Label5.height = 10
$Label5.location = New-Object System.Drawing.Point(158,77)
$Label5.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Label6 = New-Object system.Windows.Forms.Label
$Label6.text = "Deployment Duration"
$Label6.AutoSize = $true
$Label6.width = 25
$Label6.height = 10
$Label6.location = New-Object System.Drawing.Point(15,107)
$Label6.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Label6.ForeColor = "Blue"

$Label7 = New-Object system.Windows.Forms.Label
$Label7.text = Get-ItemPropertyValue -Path HKLM:\SOFTWARE\BuildInfo\ -Name "DeploymentDuration"
$Label7.AutoSize = $true
$Label7.width = 25
$Label7.height = 10
$Label7.location = New-Object System.Drawing.Point(158,107)
$Label7.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Label8 = New-Object system.Windows.Forms.Label
$Label8.text = "Task Sequence"
$Label8.AutoSize = $true
$Label8.width = 25
$Label8.height = 10
$Label8.location = New-Object System.Drawing.Point(15,137)
$Label8.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Label8.ForeColor = "Blue"

$Label9 = New-Object system.Windows.Forms.Label
$Label9.text = Get-ItemPropertyValue -Path HKLM:\SOFTWARE\BuildInfo\ -Name "TaskSequenceName"
$Label9.AutoSize = $true
$Label9.width = 25
$Label9.height = 10
$Label9.location = New-Object System.Drawing.Point(157,137)
$Label9.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "Finish"
$Button1.width = 312
$Button1.height = 29
$Button1.location = New-Object System.Drawing.Point(15,160)
$Button1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
$Button1.add_Click({$Form.Close()})

[void] $Form.ShowDialog()

Any help would be very greatfully received :) Thanks in advance

You can’t add controls to the form before they are instantiated so I moved this to just before the ShowDialog() method call and it appears to work fine.

$Form.controls.AddRange(@($Label1,$Label2,$Label3,$Label4,$Label5,$Label6,$Label7,$Label8,$Label9,$Button1))

Output
image

I did have to hard code the registry values to test since those keys don’t exist on my machine.

Thanks, i had tried this before and maks no difference :frowning:Stuck

Works fine here. What version of PS and what OS are you using?

PSVersion 5.1.14393.2879
Windows 10 2004

It works on my machine yeah, but not when trying to run at the end of a SCCM task Sequence. so the Task Sequence reboots at the end and boots using the VBS bootstrapper and then hangs unless script it ran in Max mode

Can you call the script outright (task sequence step) without the VBS bootstrapper? It probably has something to do with interacting with the desktop (creating a window) before the OS is ready. But that’s just conjecture on my part.

I will try that, But it does work but only when the form is being asked to load in Max nor Normal mode :frowning: But will give that a try anuway

There may be something to interacting with the desktop in SCCM (which I believe creating a window qualifies). According to docs for running PowerShell scripts as SCCM step:

“It shouldn’t interact with the desktop. The script must run silently or in an unattended mode.”

Also, I found an article where they use ServiceUI.exe to run the PowerShell script with custom form and had success.

ok will take a look, thanks for your time. :slight_smile: