<#
.Synopsis
Verifies if computername matches Windows machine naming requirements
.DESCRIPTION
This function accepts a computername string and regex verifies if that name meets Windows machine naming requirements
.PARAMETER ComputerName
String of computername to be tested
.EXAMPLE
Test-ComputerName -ComputerName PC-Num-43123
This will verify if the computer name meets windows requirements
.EXAMPLE
Test-ComputerName PC-Num-43123
This will verify if the computer name meets windows requirements - the -ComputerName does not have to be explicitly used
.OUTPUTS
Boolean value
.NOTES
Author: Jake Morrison
http://techthoughts.info
#>
function Test-ComputerName {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0
)]
[String]
$ComputerName
)
#assume the best
[bool]$compEval = $true
if ($computerName -notmatch '(?i)(?=.{5,15}$)^(([a-z\d]|[a-z\d][a-z\d\-]*[a-z\d])\.)*([a-z\d]|[a-z\d][a-z\d\-]*[a-z\d])$') {
$compEval = $false
}
return $compEval
}