Show Form During Logon Script

I have a powershell logon script via GPO. I would like to show a form when the script runs. Works great from the ISE but doesn’t do anything during the logon script.

Thanks for any help!

Add-Type -AssemblyName System.Windows.Forms

$form = New-Object System.Windows.Forms.Form
$form.Text = "" 
$form.Size = New-Object System.Drawing.Size(400, 800) #width, height
$form.Font = New-Object System.Drawing.Font("Comic Sans MS",16,[System.Drawing.FontStyle]::Regular)
$form.MinimizeBox = $False
$form.MaximizeBox = $False
$form.WindowState = "Normal" #Maximized, Minimized, Normal
$form.SizeGripStyle = "Hide" #Auto, Hide, Show
$form.ShowInTaskbar = $False
$form.Opacity = 1.0 #1.0 is fully opaque; 0.0 is invisible
$form.StartPosition = "CenterScreen" # CenterScreen, Manual, WindowsDefaultLocation, WindowsDefaultBounds, CenterParent

$label1 = New-Object System.Windows.Forms.label
$label1.BackColor = "Transparent"
$label1.BorderStyle = "None"
$label1.Location = New-Object System.Drawing.Point(1, 375) #left, top
$label1.Text = "Test Line 1"
$label1.TextAlign = "MiddleCenter"
$label1.Width = 800


Yeah, the ISE is not a good “testbed.” But there’s a further complexity with logon scripts where PowerShell doesn’t get front-most execution priority. There’s not actually much you can do about that, as it’s not PowerShell’s fault, but rather the way GPs are processed and given system access.

Is the goal here to collect information, or just display a message?

Ditto on the GPO preference and the .ps1 priority.
Your post runs as expected in the ISE/ConsoleHost/VSCode/PSStudio, and even from a scheduled task.
So, something else is the catch22.

Thanks for the replies. In this case the solution was simple…I just added $form.topmost to the code.

Thanks again!