Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8128561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:56:01+00:00 2026-06-06T07:56:01+00:00

Bottom Line Up Front I’m looking for a method to validate powershell (v1) command

  • 0

Bottom Line Up Front

I’m looking for a method to validate powershell (v1) command line parameters without propagating exceptions back to the command line.

Details

I have a powershell script that currently uses param in conjunction with [ValidateNotNullOrEmpty] to validate command line paramaters:

param(
   [string]
   [ValidateNotNullOrEmpty()]$domain = $(throw "Domain (-d) param required.")
)

We’re changing the paradigm of error handling where we no longer want to pass exceptions back to the command line, but rather provide custom error messages. Since the param block can not be wrapped in a try catch block, i’ve resorted to something like the following:

param(
   [string]$domain = $("")
)
Try{
   if($domain -like $("")){
      throw "Domain (-d) param required."
    }
...

}Catch{
#output error message 
}

My concern is that we’re bypassing all of the built-in validation that is available with using param. Is my new technique a reasonable solution? Is there a better way to validate command line params while encapsulating exceptions within the script? I’m very much interested in see how PowerShell professionals would handle this situation.

Any advice would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:56:03+00:00Added an answer on June 6, 2026 at 7:56 am

    As I mentioned in a comment: more I read your description, more I come to the conclusion that you should not worry about “bypassing all built-in validation”. Why? Because that’s exactly your target. You want to bypass it’s default behavior, so if that’s what you need and have to do – than just do it. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bottom Line Up Front Is there a succinct way that I can constrain the
You can skip to the bottom line if you don't care about the background:
I would like to add a data table to bottom of a (line) chart
Most popular browsers, while rendering an image, they display it line-by-line top-to-bottom as it
What is the best method to set cross-browser consistence typography (font-size and line height)
Bottom line: I have a Sub that should be re-ordering a group of records,
There is missing bottom border line gap after <dt> what is causing this and
My UITextView has only 1 line of text. But the bottom half of the
For some reason the bottom-border would not display at the bottom? The border line
I have this styling: .content .chapter_text { margin-bottom: 0em; padding: 0.5em; line-height: 1.5em; }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.