Paramater validation – size in MB

Welcome Forums General PowerShell Q&A Paramater validation – size in MB

Viewing 4 reply threads
  • Author
    Posts
    • #182766
      Participant
      Topics: 10
      Replies: 41
      Points: 213
      Helping Hand
      Rank: Participant

      I’m writing a function to set values for Exchange (quotas, etc.) – using the set-mailbox cmdlet in a larger script.

      Anyone know how to validate a parameter input is a size (like 100MB, 2GB, etc.)?

    • #182787
      Participant
      Topics: 6
      Replies: 108
      Points: 304
      Helping Hand
      Rank: Contributor

      Use a regular expression:

      Credit for the regex goes here: https://www.regextester.com/108417

    • #182790
      Participant
      Topics: 10
      Replies: 41
      Points: 213
      Helping Hand
      Rank: Participant

      Perfect!  That’s what I needed.  Thank you.

    • #182796
      Participant
      Topics: 2
      Replies: 513
      Points: 1,322
      Helping Hand
      Rank: Community Hero

      @Darwin-Reiswig might be good to use `[ValidatePattern()]` here instead:

    • #182940
      Participant
      Topics: 10
      Replies: 41
      Points: 213
      Helping Hand
      Rank: Participant

      Slick. I’ve never used validatepattern before. Learned something new today 🙂

      Thanks!

Viewing 4 reply threads
  • The topic ‘Paramater validation – size in MB’ is closed to new replies.