ValidateLength Powershell

后端 未结 3 1489
渐次进展
渐次进展 2021-01-20 18:28

This is my first script so don\'t beat me up to bad!

I\'m working on a script that creates a network directory & AD group based on user input. The following is w

3条回答
  •  盖世英雄少女心
    2021-01-20 18:51

    Although the various [Validate... attributes work on variables, it's a non-standard usage (and few people know about them). It works best when you do want to error out.

    If you don't, just check it yourself and decide and what to do in the event that it's not what you want:

    do {
        $Division = [string](Read-Host -Prompt 'Please enter the TWO digit division number ')
        if ($Divison.Length -ne 2) {
            continue
        }
    
        $Matter = [string](Read-Host -Prompt 'Please enter the FOUR digit matter number ')
        if ($Matter.Length -ne 4) {
            continue
        }
    
        $Client = [string](Read-Host -Prompt 'Please enter the FOUR digit client number ')
        if ($Client.Length -ne 4) {
            continue
        }
    
        break
    } while ($true)
    

提交回复
热议问题