Powershell parameters string or file -
i have script i'd user able come in string or utilize file(array) script can cycle through.
can done parameter?
i'd able
script.ps1 -file c:\users\joerod\desktop\listofusers.txt
or
script.ps1 -name "john doe"
sure, need pick default parameterset utilize when positional parameter used since type of both parameters string e.g.:
[cmdletbinding(defaultparametersetname="file")] param( [parameter(position=0, parametersetname="file")] [string] $file, [parameter(position=0, parametersetname="name")] [string] $name ) if ($pscmdlet.parametersetname -eq "file") { ... handle file case ... } else { ... must name case ... }
where defaultparametersetname essential when specifies this:
myscript.ps1 foo.txt
if default parametersetname specified, powershell can't tell parameterset should used since both position 0 parameters same type [string]
. there no way disambiguate parameter place argument in.
powershell parameters
No comments:
Post a Comment