powershell 测试计算机名

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 测试计算机名相关的知识,希望对你有一定的参考价值。

<#
.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
}

以上是关于powershell 测试计算机名的主要内容,如果未能解决你的问题,请参考以下文章

基于PowerShell 3.0的web接口测试

powershell v2.0 从批处理 cmd 文件传递​​变量计算机名参数

如何使用批处理或 powershell 更改 Windows PC 的主机名

powershell 性能测试小脚本

使用PowerShell解三道测试开发笔试题

Powshell查找域内计算机名帐号