Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Required Scripting Parameters in PowerShe

$
0
0

When you write a PowerShell script, you are creating something that might be executed by someone else on a totally different computer. A potential obstacle is that the person running your script may not have the necessary cmdlets or permissions for your script to run without error. Sure, you should use error handling and parameter validation, but there are additional steps you can take so that if a requirement isn't met the script won't even get started. Personally, I'd rather have a script fail to start then run part-way and then bomb out.

At the beginning of your script you can insert a few requirements. These are actually commented lines but PowerShell is designed to look for them. First off, you can require a minimum PowerShell version. If you are running a mix of PowerShell v2 and v3 computers and your script uses a v3 feature, you will want to restrict who can run your script. At the beginning of your script insert this line:

Read More 


Viewing all articles
Browse latest Browse all 6937

Trending Articles