I
Irwin
$Global:ComputerName = (Get-WmiObject win32_computerSystem).Caption
$NewComputerName = read-host "Current computer name is `"$ComputerName`".
Enter the new name (or leave blank to cancel)"
if ($NewComputerName -NE "") {
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
$ComputerInfo.rename($NewComputerName)
}
I have this code above. Need to allow only alphanumeric characters (and
maybe hyphen -) to $NewComputerName. How do I do it?
Many thanks!
$NewComputerName = read-host "Current computer name is `"$ComputerName`".
Enter the new name (or leave blank to cancel)"
if ($NewComputerName -NE "") {
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
$ComputerInfo.rename($NewComputerName)
}
I have this code above. Need to allow only alphanumeric characters (and
maybe hyphen -) to $NewComputerName. How do I do it?
Many thanks!