function Load-Form { $Form.Controls.Add($TBComputerName) $Form.Controls.Add($GBComputerName) $Form.Controls.Add($ButtonOK) $Form.Controls.Add($Label) $Form.Add_Shown({$Form.Activate()}) [void] $Form.ShowDialog() } function Set-OSDComputerName { $ErrorProvider.Clear() if ($TBComputerName.Text.Length -eq 0) { $ErrorProvider.SetError($GBComputerName, "Please enter a computer name") } else { if ($TBComputerName.Text.Length -gt 7) { $ErrorProvider.SetError($GBComputerName, "Computer name cannot be more than 6 characters") } else { if ($TBComputerName.Text -notmatch '^[F][0-9]{2,2}[a-zA-Z]{4,4}$') { $ErrorProvider.SetError($GBComputerName, "Computer name must be named with and and ") } else { $OSDComputerName = $TBComputerName.Text -replace "[\[\]:;|=+*?<>\/,]+", '' $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment $TSEnv.Value("OSDComputerName") = "$($OSDComputerName)" $Form.Close() } } } } [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $Global:ErrorProvider = New-Object System.Windows.Forms.ErrorProvider $Form = New-Object System.Windows.Forms.Form $Form.Size = New-Object System.Drawing.Size(300,300) $Form.StartPosition = "CenterScreen" $Form.SizeGripStyle = "Hide" $Form.Text = "Enter Computer Name" $Form.ControlBox = $false $Form.TopMost = $true $TBComputerName = New-Object System.Windows.Forms.TextBox $TBComputerName.Location = New-Object System.Drawing.Size(25,30) $TBComputerName.Size = New-Object System.Drawing.Size(215,50) $TBComputerName.TabIndex = "1" $GBComputerName = New-Object System.Windows.Forms.GroupBox $GBComputerName.Location = New-Object System.Drawing.Size(20,10) $GBComputerName.Size = New-Object System.Drawing.Size(225,50) $GBComputerName.Font = [System.Drawing.Font]::new("Corbel", 9, [System.Drawing.FontStyle]::Regular) $GBComputerName.Text = "Computer name:" $ButtonOK = New-Object System.Windows.Forms.Button $ButtonOK.Location = New-Object System.Drawing.Size(195,70) $ButtonOK.Size = New-Object System.Drawing.Size(50,20) $ButtonOK.Text = "OK" $ButtonOK.TabIndex = "2" $ButtonOK.Add_Click({Set-OSDComputerName}) $Label = New-Object System.Windows.Forms.Label $Label.Location = New-Object System.Drawing.Size(20,100) $Label.Size = New-Object System.Drawing.Size((225,150) ) $Label.Font = [System.Drawing.Font]::new("Corbel", 10, [System.Drawing.FontStyle]::Regular) $Label.Text = "Just some information to end users" Load-Form