function Set-OSDComputerName { $ErrorProvider.Clear() if ($TBComputerName.Text.Length -eq 0) { $ErrorProvider.SetError($GBComputerName, "Please enter a computer name") return } if ($TBComputerName.Text.Length -gt 7) { $ErrorProvider.SetError($GBComputerName, "Computer name cannot be more than 6 characters") return } 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 ") return } else { $OSDComputerName = $TBComputerName.Text -replace "[\[\]:;|=+*?<>\/,]+", '' $temp_file = $temp_path + $OSDComputerName + ".txt" if (Test-Path "\\lupinlicious\DeploymentShare$\Computers\$OSDComputerName") { $ErrorProvider.SetError($GBComputerName, "Computer name already exists. Choose another name") return } New-Item -Path "\\lupinlicious\DeploymentShare$\Computers\$OSDComputerName" -ItemType File | Out-Null $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment $TSEnv.Value("OSDComputerName") = "$($OSDComputerName)" $Form.Close() } }