![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Test for parameters in functions param($p1, $p2, $p3, $p4) function Usage { @' Syntax: powershell.exe .\testhello.ps1 p1 p2 p3 p4 -parameter p1, p2, p3, p4 are mandatory '@ exit 1 } # test for parameters function if (!$p1) { cls usage } ================================================== How can i enforce parameter p1 p2 p3 p4 needs to be there ? I don't want to write multiple function for testing p1 to p4 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Test for parameters in functions Just use following: $p1 = $(Throw "-p1 is mandatory parameter") Martin |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Q: Functions or Scripts that take parameters? | PowerShell | |||
| Call function with parameters that also call functions (.Net and P | PowerShell | |||
| Invoking PowerShell functions with parameters from .NET: issues. | PowerShell | |||
| Functions as parameters | PowerShell | |||
| Functions and ScriptBlock parameters? | PowerShell | |||