I've been developing a package using v4.0.6 to be used with Intune AutoPilot where I'm prompting the tech running the installer for information. With PSADT not having any sort of prompt to receive input from a user I'm building System.Windows.Forms to handle these requests. The script is running under System context but requires user input/interaction, so I've been relying on ServiceUI. I haven't had time to test the new version yet to see how it will handle prompts like this without the use of ServiceUI, but I figured I would at least start a discussion to see if anyone has done something similar and can answer and potentially save me a bit of time. I love the idea of no longer needing to rely on ServiceUI so if this is possible, I would love to change how I'm developing this.
Or in times like this will ServiceUI still be required?
I would love if PSADT was able to give me a customizable prompt option to request input. In my specific case I'm prompting the user for the computer name to rename the computer to and do a bunch of other functions with.
It's not the prettiest but here's the form I'm building and how it's used if anyone is interested or could use something similar for themselves.
function Get-ComputerName {
## Form to prompt for Computer Name
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
Add-Type -Assembly System.Drawing
[int32]$height = 150
[int32]$width = 350
$Line1 = "Enter the desired Computer Name"
$line2 = "Attempt $count of 3"
$FormIcon = New-Object system.drawing.icon "$($adtSession.DirFiles)\AppIcon.ico"
$objImage = [system.drawing.image]::FromFile("$($adtSession.DirFiles)\AppIcon.png")
$pictureBox = New-Object System.Windows.Forms.PictureBox
$pictureBox.Width = 60
$pictureBox.Height = 60
$pictureBox.Location = New-Object System.Drawing.Point(10,10)
$pictureBox.Image = $objImage
$pictureBox.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(80,65)
$textBox.Size = New-Object System.Drawing.Size(190,20)
$label = New-Object System.Windows.Forms.Label
$label.Font = 'Microsoft Sans Serif,10'
$label.width = 400
$label.height = 25
$label.Location = New-Object System.Drawing.Point(80,10)
$label.Text = $Line1
$label2 = New-Object System.Windows.Forms.Label
$label2.Font = 'Microsoft Sans Serif,10'
$label2.width = 400
$label2.height = 25
$label2.Location = New-Object System.Drawing.Point(80,35)
$label2.Text = $Line2
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(30,100)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(245,100)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$Form = [System.Windows.Forms.Form]::new()
$form.SuspendLayout()
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$Form.ClientSize = "$width,$height"
$Form.text = "Rename Computer"
$Form.Icon = $FormIcon
$form.Controls.Add($pictureBox)
$form.Controls.Add($textBox)
$form.AcceptButton = $OKButton
$form.CancelButton = $cancelButton
$form.Controls.Add($label)
$form.Controls.Add($label2)
$Form.controls.Add($OKButton)
$Form.controls.Add($cancelButton)
$form.Add_Shown({$textBox.Select()})
$Form.BringToFront()
$Form.TopMost = $true
$Form.ResumeLayout()
$Result = $Form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
If (($textBox.Text -eq "") -or ($null -eq $textBox.Text)) {
$ComputerName = $Null
Write-ADTLogEntry -Message "User entered no data. Attempt $Count of 3." -Source 'Computer Name GUI Prompt'
Write-Output $ComputerName
}
Else {
$ComputerName = $textBox.Text
Write-ADTLogEntry -Message "User entered computer name: $ComputerName" -Source 'Computer Name GUI Prompt'
Write-Output $ComputerName
}
}
Else {
$ComputerName = $Null
Write-ADTLogEntry -Message "User cancelled the prompt. Attempt $Count of 3." -Source 'Computer Name GUI Prompt'
Write-Output $ComputerName
}
}
## Gather computer name and ensure it valid contains data. Give 3 attempts before existing script
$Count = 0
do {
$Count = $Count+1
$Name = Get-ComputerName
If ($Name -match "\s") {
Write-ADTLogEntry -Message "Computer name entered contained spaces, please try again without spaces. Name entered: $Name" -Severity 2 -Source 'Computer Name GUI Prompt'
Show-ADTDialogBox "Computer name entered contained spaces, please try again without spaces.`n`nName entered: $Name" -Title "Rename Computer" -Icon Stop
$Name = $null
}
If ($Name.Length -gt "15") {
Write-ADTLogEntry -Message "Computer name entered is longer than 15 characters, please try again with a shorter name. Name entered: $Name" -Severity 2 -Source 'Computer Name GUI Prompt'
Show-ADTDialogBox "Computer name entered is longer than 15 characters, please try again with a shorter name.`n`nName entered: $Name" -Title "Rename Computer" -Icon Stop
$Name = $null
}
} until (($null -ne $Name) -or ($count -ge "3"))
If ($null -eq $Name) {
Write-ADTLogEntry -Message "Computer Name prompt cancelled after $count attempts, exiting deployment." -Severity 3 -Source 'Computer Name GUI Prompt'
Show-ADTDialogBox "Computer name prompt cancelled after $count attempts, exiting deployment." -Title "Rename Computer" -Icon Stop
Close-ADTSession -ExitCode 1603
}