根据BIOS信息修改主机名
Dell: Rename-Computer -NewName ("CNHZPD-" + (Get-WmiObject -class win32_Bios).SerialNumber.substring(0,7)) -Restart Lenovo: $parttern_ln="\b\D{2}\d{8}\b" $parttern_tp="\b\w{7}\b" $biosname = (Get-WmiObject -Class win32_Bios).serialnumber $baseboardname = (Get-WmiObject -Class win32_BaseBoard).serialnumber if ($biosname -match $parttern_ln) { Rename-Computer -NewName ("CNHZLN-" + $biosname.Substring(2,8)) -Restart } elseif($baseboardname -match $parttern_ln) { Rename-Computer -NewName ("CNHZLN-" + $baseboardname.Substring(2,8)) -Restart } elseif($biosname -match $parttern_tp) { Rename-Computer -NewName ("CNHZLN-" + $biosname) -Restart } else {Write-Host "Sorry"}