1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

powershellの文法の調べ方

Posted at

はじめに

powershellのhelpはわかりにくいので今日気がついた、方法をup

powershellの引数とhelp

powershellでは、例えば次のような関数を作成すると自動的にhelpを作ってくれる

function
function test($x,$y="def"){
  echo $x $y
}

ヘルプの内容

>help test 
NAME
  test
SYNTAX
  test [-x] <object> [[-y] <object>]
PARAMETERS
  -x <object>
     Required?   true
     position    0
     省略
 -y <object>
     Required?   false
     position    1
      省略

そうなのである。functionで
test 1 2
とかで使おうと思っていた関数が
test -x 1 -y 2
というように呼ぶことができるのだ。これを知っていると次の応用ができる。

通常のコマンドの調べ方

つまり、いちいち、-xxxを指定しない方法は「position」を検索すればいいということになる。
そこで、
help ls | position
とすると、pathが1番目、filterが2番目とわかるので

ls . *.bat
とかすれば、okであるというのが分かる。
めでたしめでたし。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?