0
1

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 1 year has passed since last update.

PowerShellメモ

Posted at

PowerShellの文

PowerShellの式を改行すると文となる。
PowerShellの式が文となり値を持つ場合はそれがコンソールに出力される。
このとき単純にコンソールに値を出力するだけであれば特別な出力コマンドレットを使用する必要はない。

以下はミニマリスト的なPowerShellのHello Worldである。

hello.ps1
"hello"

PowerShellのスクリプトに渡された引数にアクセスするには$args[]配列を使用する。

$args[]は配列なので0から始まり自分のスクリプト名自身は含まれない。
引数の数を調べるには .Length プロパティを使用する。

hello.ps1
"hello"
$args.Length
$args[0]
$args[1]
$args[2]
"world"

一方でより柔軟に引数を扱えるParamsもある。
これについては後報する。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?