How can I check if a string is null or empty in PowerShell?

后端 未结 11 1047
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 04:49

Is there a built-in IsNullOrEmpty-like function in order to check if a string is null or empty, in PowerShell?

I could not find it so far and if there i

11条回答
  •  执念已碎
    2020-12-02 04:50

    If it is a parameter in a function, you can validate it with ValidateNotNullOrEmpty as you can see in this example:

    Function Test-Something
    {
        Param(
            [Parameter(Mandatory=$true)]
            [ValidateNotNullOrEmpty()]
            [string]$UserName
        )
    
        #stuff todo
    }
    

提交回复
热议问题