This topic contains 3 replies, has 3 voices, and was last updated by
July 19, 2018 at 3:32 pm #104719ParticipantPoints: 0Rank: Member
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
July 19, 2018 at 7:11 pm #104755KeymasterPoints: 1,625Rank: Community Hero
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?
July 20, 2018 at 2:07 am #104791ParticipantPoints: 221Rank: Participant
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.
July 20, 2018 at 1:15 pm #104819ParticipantPoints: 0Rank: Member
Thanks for the replies. In this case the solution was simple...I just added $form.topmost to the code.
The topic ‘Show Form During Logon Script’ is closed to new replies.