2

I have a script that accepts one or more subdomains, I want to validate them but [ValidatePattern()] seems to only check the first item in the array.

The code:

param(
    [ValidatePattern('\w*\.domain\.com')][string]$subdomain
)

This input gets accepted:

.\script.ps1 -subdomain "test.domain.com", "randomstring"

Is there a way to validate every entry in the array?

1 Answer 1

6
param(
    [ValidatePattern('\w*\.domain\.com')][string[]]$subdomain
)

in your script subdomain parameter doesn't accept multiple values. [string[]]$subdomain

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.