I'm in the process of converting a Korn shell script to PowerShell. The existing script utilizes the getopt command and makes use of case sensitive command line arguments (e.g., v behaves differently than V).
set -- `getopt T:ZISedDACkpWhzLJMl:n:g:x:r:R:V:v:N:G:o:m:O: $*`
for c in $*
do
case $c in
-h) echo $USAGE
--) shift; break;;
esac
done
For the PowerShell version, I would like to keep the parameter names and behavior exactly the same. I've been investigating Named Function Parameters as a possibility; however, PowerShell is case insensitive and will not allow the duplicate parameter names. So, this will not work.
function dowork ()
{
param
(
[string]$V,
[string]$v,
)
...
}
I could utilize the automatic $args variable which contains an array of the undeclared parameters; however, I am not aware of a PowerShell equivalent for the getopt command. Is there another way to accomplish this without implementing my own getopt?