M
M
m00nkey2014-08-05 09:56:53
PowerShell
m00nkey, 2014-08-05 09:56:53

How to call a script with an argument in powershell?

Good day!
Wrote a bash script

start) {
бла-бла
}
stop) {
бла-бла
}
restart) {
бла-бла
}
case "$1" in
 
   start)
       start
       ;;
   stop)
       stop
       ;;
   restart)
      restart
       ;;
    *)

how to do the same in powershell? so that when a script is called with the stop\start\restart key, a certain piece of code is executed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly, 2014-11-19
@m00nkey

[CmdletBinding()]
Param(
    [Parameter(Mandatory=$True,Position=1)]
    [String]$worktype
)

switch ($worktype) {
    'start'  {
        Write-Host 'start'
    }
    'stop' {
        Write-Host 'stop'
    }
    'restart' {
        Write-Host 'restart'
    }
}

B
bmforce, 2014-08-05
@bmforce

You can use the $args variable
$action=$args[0]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question