OSDComputerName.ps1

Param(
    [string]$Value
)

$BadChars = @(
	"\",
	"/",
	":",
	"*",
	"?",
	"!",
	" ",
	"'",
	'"',
	"<",
	">",
	"|",
	"_",
	".",
	",",
	"~",
	"@",
	"#",
	"$",
	"%",
	"^",
	"&",
	"(",
	")",
	"{",
	"}"
)


$CharResult=$true
$Result=$True
$Buttons = [System.Windows.Forms.MessageBoxButtons]::OK
$Icon = [System.Windows.Forms.MessageBoxIcon]::Error
$Title = "Error"


# Test for bad chars
$Value.tochararray() | ForEach-Object{If($_ -in $BadChars){$CharResult=$False}}
If($CharResult -eq $false){
    [System.Windows.Forms.MessageBox]::Show("The computer name cannot contain any of the following: $($BadChars -join ', ')",$Title,$Buttons,$Icon) | Out-Null
    $Result=$false
}

$Result

Document Actions