$SerialNumber = (Get-WmiObject -Class Win32_BIOS | Select-Object SerialNumber).SerialNumber <# Start you Copy from here .NOTES -------------------------------------------------------------------------------- GUI (Windows Forms) generated by: PowerShell Studio 2014 v4.1.60 Code logic by: Michael Buchardt Organization: Mimercon -------------------------------------------------------------------------------- #> #---------------------------------------------- #region Application Functions #---------------------------------------------- #endregion Application Functions #---------------------------------------------- # Generated Form Function #---------------------------------------------- function Call-ComputerNamePrompter_psf { #---------------------------------------------- #region Import the Assemblies #---------------------------------------------- [void][reflection.assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') [void][reflection.assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') #endregion Import Assemblies #---------------------------------------------- #region Generated Form Objects #---------------------------------------------- [System.Windows.Forms.Application]::EnableVisualStyles() $Blog = New-Object 'System.Windows.Forms.Form' $buttonRunOSDeployment = New-Object 'System.Windows.Forms.Button' $textbox1 = New-Object 'System.Windows.Forms.TextBox' $labelPleaseEnterAComputer = New-Object 'System.Windows.Forms.Label' $errorprovider1 = New-Object 'System.Windows.Forms.ErrorProvider' $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' #endregion Generated Form Objects #---------------------------------------------- # User Generated Script #---------------------------------------------- $OnLoadFormEvent={ #Hide the task sequence progress dialog until next step $TSProgressUI = new-object -comobject Microsoft.SMS.TSProgressUI $TSProgressUI.CloseProgressDialog() } function Validate-IsEmptyTrim ([string] $field) { if(($field -eq $null) -or ($field.Trim().Length -eq 0) -or ($field.Trim().Length -lt 15) -or ($field -match "^[-_]|[^a-zA-Z0-9-_]")) { return $true } return $false } $labelPleaseEnterAComputer_Click={ } $textbox1_TextChanged={ #Clear the error message $errorprovider1.SetError($textbox1, ""); } $buttonRunOSDeployment_Click={ #Get Computer Name from input $NewComputerName = $textbox1.Text #Send Computer Name to SCCM TS $tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment $tsenv.Value("OSDComputerName") = "$NewComputerName" #$tsenv.Value("OSDComputerName") = "$($NewComputerName)" #Close form and Exit Script when RunOSDeployButton is clicked $Blog.Close() #Write-Host $NewComputerName #Write-Host $tsenv.Value("OSDComputerName") } $textbox1_Validating=[System.ComponentModel.CancelEventHandler]{ #Event Argument: $_ = [System.ComponentModel.CancelEventArgs] #Check if the Name field is empty $result = Validate-IsEmptyTrim $textbox1.Text if($result -eq $true) { #Display an error message $errorprovider1.SetError($textbox1, "Введено меньше 15 символов или в имени присутствуют спецсимволы"); $_.Cancel = $true } else { #Clear the error message $errorprovider1.SetError($textbox1, ""); } } # --End User Generated Script-- #---------------------------------------------- #region Generated Events #---------------------------------------------- $Form_StateCorrection_Load= { #Correct the initial state of the form to prevent the .Net maximized form issue $Blog.WindowState = $InitialFormWindowState } $Form_Cleanup_FormClosed= { #Remove all event handlers from the controls try { $buttonRunOSDeployment.remove_Click($buttonRunOSDeployment_Click) $textbox1.remove_TextChanged($textbox1_TextChanged) $textbox1.remove_Validating($textbox1_Validating) $labelPleaseEnterAComputer.remove_Click($labelPleaseEnterAComputer_Click) $Blog.remove_Load($OnLoadFormEvent) $Blog.remove_Load($Form_StateCorrection_Load) $Blog.remove_FormClosed($Form_Cleanup_FormClosed) } catch [Exception] { } } #endregion Generated Events #---------------------------------------------- #region Generated Form Code #---------------------------------------------- $Blog.SuspendLayout() # # Blog # $Blog.Controls.Add($buttonRunOSDeployment) $Blog.Controls.Add($textbox1) $Blog.Controls.Add($labelPleaseEnterAComputer) $Blog.AcceptButton = $buttonRunOSDeployment $Blog.ClientSize = '364, 181' $Blog.ControlBox = $False $Blog.Font = "Microsoft Sans Serif, 11pt" $Blog.KeyPreview = $True $Blog.MaximizeBox = $False $Blog.MinimizeBox = $False $Blog.Name = "Blog" $Blog.ShowIcon = $False $Blog.StartPosition = 'CenterScreen' # Edit the line below to change the text (Form Name) $Blog.Text = "Введите имя компьютера, SN = " + $SerialNumber # Edit End $Blog.add_Load($OnLoadFormEvent) # # buttonRunOSDeployment # $buttonRunOSDeployment.Font = "Microsoft Sans Serif, 14pt, style=Bold" $buttonRunOSDeployment.ForeColor = 'MenuHighlight' $buttonRunOSDeployment.Location = '97, 98' $buttonRunOSDeployment.Name = "buttonRunOSDeployment" $buttonRunOSDeployment.Size = '167, 68' $buttonRunOSDeployment.TabIndex = 2 # Edit the line below to change the text (Button) # "Run OS deployment" $buttonRunOSDeployment.Text = "Продолжить" # Edit End $buttonRunOSDeployment.UseVisualStyleBackColor = $True $buttonRunOSDeployment.add_Click($buttonRunOSDeployment_Click) # # textbox1 # $textbox1.AcceptsReturn = $True $textbox1.Font = "Microsoft Sans Serif, 12pt" $textbox1.Location = '82, 46' $textbox1.MaxLength = 15 $textbox1.Name = "textbox1" $textbox1.Size = '195, 29' $textbox1.TabIndex = 1 #$textbox1.Text = $SerialNumber $textbox1.SelectedText = $SerialNumber $textbox1.add_TextChanged($textbox1_TextChanged) $textbox1.add_Validating($textbox1_Validating) # # labelPleaseEnterAComputer # $labelPleaseEnterAComputer.Font = "Microsoft Sans Serif, 16pt, style=Bold" $labelPleaseEnterAComputer.Location = '35, 9' $labelPleaseEnterAComputer.Name = "labelPleaseEnterAComputer" $labelPleaseEnterAComputer.Size = '339, 34' $labelPleaseEnterAComputer.TabIndex = 0 # Edit the line below to change the text # "Please enter a computer name" $labelPleaseEnterAComputer.Text = "Введите имя компьютера" # Edit end $labelPleaseEnterAComputer.add_Click($labelPleaseEnterAComputer_Click) # # errorprovider1 # $errorprovider1.BlinkStyle = 'AlwaysBlink' $errorprovider1.ContainerControl = $Blog $Blog.ResumeLayout() #endregion Generated Form Code #---------------------------------------------- #Save the initial state of the form $InitialFormWindowState = $Blog.WindowState #Init the OnLoad event to correct the initial state of the form $Blog.add_Load($Form_StateCorrection_Load) #Clean up the control events $Blog.add_FormClosed($Form_Cleanup_FormClosed) #Show the Form return $Blog.ShowDialog() } #End Function #Call the form Call-ComputerNamePrompter_psf | Out-Null #End you copy here