3

I have a caller.cmd file which has a DOSKEY set like this:

DOSKEY startnow=call powershell getscalled.ps1 

Now the script getscalled.ps1 has two switch parameters defined in parameter sets like this:

param(
    [Parameter(Mandatory=$false,ParameterSetName='first')]
    [switch]$thisIsFirst,
    [Parameter(Mandatory=$false,ParameterSetName='second')]
    [switch]$thisIsSecond
) 

So, only one of the two parameters can be provided at a time. I want the parameter to be provided from the command line itself using the DOSKEY that I have set up. Something like:

startnow -thisIsFirst  

Any help on how to achieve this? Thanks!

aschipfl
  • 33,626
  • 12
  • 54
  • 99
cs_love
  • 35
  • 6

1 Answers1

12

Create macro like this(so use $1 $2... for parameters);

DOSKEY startnow=script.ps1 $1

So, you could call;

startnow -thisIsFirst  
subcoder
  • 636
  • 8
  • 15
  • 4
    Yes, and I checked more on this and found that `$*` at the end will accept any number of arguments. But I have a weird issue. I have to use `==` instead of `=`, i.e. `DOSKEY startnow==call powershell getscalled.ps1 $*`. It doesn't work otherwise. What is the difference of `=` and `==` here? Any idea? – cs_love Jun 01 '20 at 19:15
  • What is your windows version? I think you do not need that "call powershell" part. – subcoder Jun 01 '20 at 20:13
  • 1
    The second = is the beginning of your command and is ignored by cmd.exe. –  Jun 01 '20 at 20:17