If your like me you have slowly (or maybe quickly) been getting frustrated with using arguments in your PowerShell scripts, they have none of the nice built in functionality that function parameters have like Named, Mandatory, etc.
On the Pro side I am grateful that they are collected into an array so that I can easily manipulate them.
Because of this I have recently found myself asking what are arguments good for? If you think about it arguments are a quick way to get one to many variables into your script, and really it is simple enough for admins of all knowledge levels to use. However they don’t present any improvements from the VBScript days which makes me wonder why not.
I believe that it comes down to one of the following elements writing style, or needed functionality.
Arguments have been made common place and popular, many admins will feel comfortable using them in PowerShell scripts since they used them in there VBScripts and batch files. I don’t see a caveat, if your comfortable in your writing style and using arguments then go for it. However if you want to step out of your comfort zone I think you will find that there are other great choices that could replace arguments for you in the future.
What is your script doing? Who is using the script? Is it for an automation project?
Arguments are really only handy if you enter all the arguments and in the correct order which means it lends itself to batching but not actual human interaction as well optional variables could be troublesome. But if you need to have a user enter the info ie User Creation you can write a function like the following to create an Input Box which will present your users with an input box where they can enter the info and you can present reminders to what info you are looking for, or maybe your skillset is set at a lower bar then I would suggest using a line like this
$ServiceAccountUserName = Read-Host “Please enter Username for Excel Service:”
Write-Host “This account name is required and should already be created in Active Directory.”
Write-Host “Please enter in the format Domain\Username”
$ServiceAccountUserName = Read-Host “Please enter Username for Excel Service:
If you do choose to still use arguments I would suggest that you write a layer to do things like insure your getting all of the required arguments, and arguments were entered in the correct order and in the correct format.