Windows PowerShell
powershell
- C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe /?
Output:
PowerShell[.exe] [-PSConsoleFile <ファイル> | -Version <バージョン>]
[-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive]
[-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
[-WindowStyle <スタイル>] [-EncodedCommand <Base64 エンコードのコマンド>]
[-ConfigurationName <文字列>]
[-File <ファイル パス> <引数>] [-ExecutionPolicy <実行ポリシー>]
[-Command { - | <スクリプト ブロック> [-args <引数の配列>]
| <文字列> [<コマンド パラメーター>] } ]
PowerShell[.exe] -Help | -? | /?
-PSConsoleFile
指定された Windows PowerShell コンソール ファイルを読み込みます。コンソー
ル ファイルの作成には、Windows PowerShell の Export-Console を使用します。
-Version
指定されたバージョンの Windows PowerShell を起動します。
このパラメーターでバージョン番号 ("-version 2.0" など) を入力します。
-NoLogo
スタートアップ時に著作権の見出しを非表示にします。
-NoExit
スタートアップ コマンドを実行後、終了しません。
-Sta
シングルスレッド アパートメントを使用して、シェルを起動します。
既定ではシングルスレッド アパートメント (STA) です。
-Mta
マルチスレッド アパートメントを使用して、シェルを起動します。
-NoProfile
Windows PowerShell プロファイルを読み込みません。
-NonInteractive
ユーザーに対話的なプロンプトを表示しません。
-InputFormat
Windows PowerShell に送られたデータの形式を指定します。有効な値は、"Text"
(テキスト文字列) または "XML" (シリアル化 CLIXML 形式) です。
-OutputFormat
Windows PowerShell からの出力の形式を決定します。有効な値は、"Text" (テ
キスト文字列) または "XML" (シリアル化 CLIXML 形式) です。
-WindowStyle
ウィンドウ スタイルを Normal、Minimized、Maximized、または Hidden に設定します。
-EncodedCommand
Base-64 エンコードの文字列のコマンドを受け付けます。複雑な引用符や中かっ
こが必要なコマンドを Windows PowerShell に送るには、このパラメーターを使
用します。
-ConfigurationName
Windows PowerShell が実行される構成エンドポイントを指定します。
ローカル コンピューターに登録された任意のエンドポイントを指定できます。
たとえば、既定の Windows PowerShell リモート処理エンドポイントや、特定の
ユーザー機能を持つカスタム エンドポイントなどを指定できます。
-File
指定されたスクリプトをローカル スコープ ("ドット ソース") で実行して、
スクリプトによって作成された関数と変数を現在のセッションで使用できるように
します。スクリプト ファイルのパスとパラメーターを入力します。
File はコマンド内で最後のパラメーターである必要があります。File パラメーター
名の後に入力された文字は、スクリプト ファイルのパスとスクリプトのパラメー
ターとして解釈されるためです。
-ExecutionPolicy
現在のセッションの既定の実行ポリシーを設定し、
$env:PSExecutionPolicyPreference 環境変数に保存します。
このパラメーターでは、レジストリに設定されている Windows PowerShell 実行
ポリシーは変更されません。
-Command
PowerShell のコマンド プロンプトに入力された場合と同様に、指定されたコマ
ンド (および任意のパラメーター) を実行します。NoExit が指定されていない場
合は、そのまま終了します。Command の値には、"-"、文字列、またはスクリプト
ブロックを指定できます。
Command の値が "-" の場合、コマンド テキストは標準入力から読み込まれます。
Command の値がスクリプト ブロックの場合は、スクリプト ブロックを中かっこ
({}) で囲む必要があります。スクリプト ブロックを指定できるのは、Windows
PowerShell で PowerShell.exe を実行している場合だけです。スクリプト ブロ
ックの結果は、ライブ オブジェクトではなく逆シリアル化 XML オブジェクトと
して親シェルに返されます。
Command の値が文字列の場合、Command はコマンド内で最後のパラメーターである
必要があります。コマンドの後に入力された文字は、コマンド引数として解釈さ
れるためです。
Windows PowerShell コマンドを実行する文字列を記述するには、次の形式を使用します。
"& {<コマンド>}"
引用符によりこれが文字列であることを示し、呼び出し演算子 (&) によりコマ
ンドが実行されます。
-Help, -?, /?
このメッセージを表示します。Windows PowerShell で PowerShell.exe のコマン
ドを入力する場合、コマンド パラメーターの前にスラッシュ (/) ではなくハイ
フン (-) を入力してください。Cmd.exe では、ハイフンまたはスラッシュのいずれかを使用できます。
例
PowerShell -PSConsoleFile SqlSnapIn.Psc1
PowerShell -version 2.0 -NoLogo -InputFormat text -OutputFormat XML
PowerShell -ConfigurationName AdminRoles
PowerShell -Command {Get-EventLog -LogName security}
PowerShell -Command "& {Get-EventLog -LogName security}"
# -EncodedCommand パラメーターを使用する場合:
$command = 'dir "c:\program files" '
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
powershell.exe -encodedCommand $encodedCommand
PowerShell[.exe] [-PSConsoleFile <file> | -Version <version>]
[-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive]
[-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
[-WindowStyle <style>] [-EncodedCommand <Base64EncodedCommand>]
[-ConfigurationName <string>]
[-File <filePath> <args>] [-ExecutionPolicy <ExecutionPolicy>]
[-Command { - | <script-block> [-args <arg-array>]
| <string> [<CommandParameters>] } ]
PowerShell[.exe] -Help | -? | /?
-PSConsoleFile
Loads the specified Windows PowerShell console file. To create a console
file, use Export-Console in Windows PowerShell.
-Version
Starts the specified version of Windows PowerShell.
Enter a version number with the parameter, such as "-version 2.0".
-NoLogo
Hides the copyright banner at startup.
-NoExit
Does not exit after running startup commands.
-Sta
Starts the shell using a single-threaded apartment.
Single-threaded apartment (STA) is the default.
-Mta
Start the shell using a multithreaded apartment.
-NoProfile
Does not load the Windows PowerShell profile.
-NonInteractive
Does not present an interactive prompt to the user.
-InputFormat
Describes the format of data sent to Windows PowerShell. Valid values are
"Text" (text strings) or "XML" (serialized CLIXML format).
-OutputFormat
Determines how output from Windows PowerShell is formatted. Valid values
are "Text" (text strings) or "XML" (serialized CLIXML format).
-WindowStyle
Sets the window style to Normal, Minimized, Maximized or Hidden.
-EncodedCommand
Accepts a base-64-encoded string version of a command. Use this parameter
to submit commands to Windows PowerShell that require complex quotation
marks or curly braces.
-ConfigurationName
Specifies a configuration endpoint in which Windows PowerShell is run.
This can be any endpoint registered on the local machine including the
default Windows PowerShell remoting endpoints or a custom endpoint having
specific user role capabilities.
-File
Runs the specified script in the local scope ("dot-sourced"), so that the
functions and variables that the script creates are available in the
current session. Enter the script file path and any parameters.
File must be the last parameter in the command, because all characters
typed after the File parameter name are interpreted
as the script file path followed by the script parameters.
-ExecutionPolicy
Sets the default execution policy for the current session and saves it
in the $env:PSExecutionPolicyPreference environment variable.
This parameter does not change the Windows PowerShell execution policy
that is set in the registry.
-Command
Executes the specified commands (and any parameters) as though they were
typed at the Windows PowerShell command prompt, and then exits, unless
NoExit is specified. The value of Command can be "-", a string. or a
script block.
If the value of Command is "-", the command text is read from standard
input.
If the value of Command is a script block, the script block must be enclosed
in braces ({}). You can specify a script block only when running PowerShell.exe
in Windows PowerShell. The results of the script block are returned to the
parent shell as deserialized XML objects, not live objects.
If the value of Command is a string, Command must be the last parameter
in the command , because any characters typed after the command are
interpreted as the command arguments.
To write a string that runs a Windows PowerShell command, use the format:
"& {<command>}"
where the quotation marks indicate a string and the invoke operator (&)
causes the command to be executed.
-Help, -?, /?
Shows this message. If you are typing a PowerShell.exe command in Windows
PowerShell, prepend the command parameters with a hyphen (-), not a forward
slash (/). You can use either a hyphen or forward slash in Cmd.exe.
EXAMPLES
PowerShell -PSConsoleFile SqlSnapIn.Psc1
PowerShell -version 2.0 -NoLogo -InputFormat text -OutputFormat XML
PowerShell -ConfigurationName AdminRoles
PowerShell -Command {Get-EventLog -LogName security}
PowerShell -Command "& {Get-EventLog -LogName security}"
# To use the -EncodedCommand parameter:
$command = 'dir "c:\program files" '
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
powershell.exe -encodedCommand $encodedCommand
Return Code: 0
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
c:\>ver
Microsoft Windows [Version 10.0.19045.2075]
| File | Info |
|---|---|
| File Size | 452608bytes |
| Creation Time | 2022/07/08 08:51:22 |
| LastWrite Time | 2022/07/08 08:51:22 |
| ProductVersion | 10.0.19041.1889 |
| FileVersion | 10.0.19041.1889 (WinBuild.160101.0800) |
| Hash | Value |
|---|---|
| MD5 | 04029e121a0cfa5991749937dd22a1d9 |
| SHA1 | f43d9bb316e30ae1a3494ac5b0624f6bea1bf054 |
| SHA224 | 3000f950d7f79c379c911c0f96194a58adeb9093ddb2574542f95cb3 |
| SHA256 | 9f914d42706fe215501044acd85a32d58aaef1419d404fddfa5d3b48f66ccd9f |
| SHA384 | 13be484f0cbe81e41d98b78ece5ec7d7434c3aeefdd37a4094d5d53f4119bf059c758647ac224bf7a7625c00435afa1a |
| SHA512 | 6a2fb055473033fd8fdb8868823442875b5b60c115031aaeda688a35a092f6278e8687e2ae2b8dc097f8f3f35d23959757bf0c408274a2ef5f40ddfa4b5c851b |