cs_love
cs_love

Reputation: 55

How to pass command line arguments to a PowerShell script invoked by a doskey

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!

Upvotes: 5

Views: 3864

Answers (1)

subcoder
subcoder

Reputation: 654

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

DOSKEY startnow=script.ps1 $1

So, you could call;

startnow -thisIsFirst  

Upvotes: 14

Related Questions