Skip to content

Instantly share code, notes, and snippets.

@midnightfreddie
Last active May 22, 2016 19:15
Show Gist options
  • Save midnightfreddie/238297db30e40ba18b676ff83a8e1465 to your computer and use it in GitHub Desktop.
Save midnightfreddie/238297db30e40ba18b676ff83a8e1465 to your computer and use it in GitHub Desktop.
Add-Type -TypeDefinition @"
public enum PcType {
DESKTOP,
LAPTOP
}
"@
$PcChoices = [System.Enum]::GetValues([type]"PcType")
# '^(DESKTOP|LAPTOP)\d{6}$' , but this lets us add/modify enum choices later with no code changes
$RegExMatch = "^({0})\d{{6}}$" -f ( ( $PcChoices | ForEach-Object { $_.ToString() } ) -join "|")
do {
if ( $i ) { Write-Host "`nYou entered invalid data. Please try again.`n" }
Write-Host "Valid choices:"
for ($i = 1; $i -le $PcChoices.Count; $i++) {
Write-Host ("{0}.`t{1}" -f $i, $PcChoices[$i-1])
}
$Type = Read-Host "Enter PC Type: "
$Code = Read-Host "Enter 6 digit code"
$ComputerName = "{0}{1}" -f $PcChoices[$Type - 1], ([int]$Code).ToString("000000")
} until ($ComputerName -cmatch $RegExMatch)
$ComputerName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment