LoginSignup
10

More than 5 years have passed since last update.

PowerShellのコマンドラインオプション

Last updated at Posted at 2016-03-16

PowerShellのコマンドラインオプションについてメモ。

コマンドラインオプションを調べるには"-?"オプションを指定する

c:> powershell.exe -?
PowerShell[.exe] [-PSConsoleFile <ファイル> | -Version <バージョン>]
    [-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive]
    [-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
    [-WindowStyle <スタイル>] [-EncodedCommand <Base64 エンコードのコマンド>]
    [-File <ファイル パス> <引数>] [-ExecutionPolicy <実行ポリシー>]
    [-Command { - | <スクリプト ブロック> [-args <引数の配列>]
                  | <文字列> [<コマンド パラメーター>] } ]
(以下説明が続く)

コマンドラインオプションは、大文字と小文字を区別しない様子。また一意に定まる前方数文字だけ指定すればいい。たとえば、vSphere PowerCLIのプロンプトを起動するショートカットは、以下になっていた。

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noe -c ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\""

このnoe-NoExitと同じ。-c-Commandと同じ。ここで-nだけだと-NoLogoとどちらか区別できないので、エラーになった。

C:>powershell.exe -n
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS C:\Users\ap745667> -n : 用語 '-n' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、再試行してください。
発生場所 行:1 文字:1
+ -n
+ ~~

PowerShell ISEでも"-?"でコマンドラインオプションを確認できる。こちらはかなり少なかった。

c:> powershell_ise.exe -?
powershell_ise.exe [[-File] <ListOfFiles>] [-Help] [-MTA] [-NoProfile]

確認環境:PowerShell 3.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
10