Powershell String Length Validation
问题 I created a really simple HelloWorld.ps1 Power-shell script which accepts a Name parameter, validates its length and then prints a hello message, for example if you pass John as Name , it's supposed to print Hello John! . Here is the Power-shell script: param ( [parameter(Mandatory=$true)] [string] $Name ) # Length Validation if ($Name.Length > 10) { Write-Host "Parameter should have at most 10 characters." Break } Write-Host "Hello $Name!" And here is the command to execute it: .\HelloWorld