I'm trying to port some perl code to powershell. However, I don't know how to implement optional arguments in powershell?
In perl, My code does something like this below, which allows me to call the script as:
myscript -z -in myin
or with optional argument:
myscript -z myz -in myin
Here's how I do this in perl:
#!/usr/local/bin/perl
# PERL CODE
use Getopt::Long;
GetOptions(
'z:s' => \$zip,
'h' => \$help,
'in=s' => \$input_dir,
);
# Using a colon (:s) instead of the equals sign (=s)
# indicates that the option value is optional. In
# this case, if no suitable value is supplied,
# string valued options get an empty string ''.
However in powershell i'm not sure how to get the functionality of ":s" in perl. Here's my Powershell code that attempts to do the same thing:
# Powershell
param(
[string] [optional???] $zip = "hello",
[switch]$h,
[string]$input_dir
)
Is there a way to do this in powershell?