PowerShell.exe 主控台說明
從其他工具 (例如 Cmd.exe) 的命令列啟動 Windows PowerShell。
語法
PowerShell[.exe]
[-PSConsoleFile <file> | -Version <version>]
[-EncodedCommand <Base64EncodedCommand>]
[-ExecutionPolicy <ExecutionPolicy>]
[-File <filePath> <args>]
[-InputFormat {Text | XML}]
[-NoExit]
[-NoLogo]
[-NonInteractive]
[-NoProfile]
[-OutputFormat {Text | XML}]
[-Sta]
[-WindowStyle <style>]
[-Command { - | <script-block> [-args <arg-array>]
| <string> [<CommandParameters>] } ]
PowerShell[.exe] -Help | -? | /?
參數
-EncodedCommand
接受命令的 Base-64 編碼字串版本。使用這個參數可以對 Windows PowerShell 發出需要複雜引號或大括號的命令。
-ExecutionPolicy
設定工作階段的預設執行原則。這個參數並不會變更在登錄中設定的 Windows PowerShell 執行原則。
-File
執行指定的指令碼。請輸入指令檔路徑和任何參數。
-InputFormat
說明傳送到 Windows PowerShell 的資料格式。有效值為 "Text" (文字字串) 或 "XML" (序列化 CLIXML 格式)。
-NoExit
執行啟動命令後不要結束。
-NoLogo
啟動時隱藏著作權橫幅。
-NonInteractive
不向使用者顯示互動式提示。
-NoProfile
不要載入 Windows PowerShell 設定檔。
-OutputFormat
決定 Windows PowerShell 的輸出格式。有效值為 "Text" (文字字串) 或 "XML" (序列化 CLIXML 格式)。
-PSConsoleFile
載入指定的 Windows PowerShell 主控台檔案。如果要建立主控台檔案,請使用 Windows PowerShell 中的 Export-Console Cmdlet。
-Sta
使用單一執行緒 Apartment 啟動殼層。
-Version
啟動指定的 Windows PowerShell 版本。請使用參數輸入版本號碼,例如 "-version 1.0"。
-WindowStyle
將視窗樣式設定為 Normal、Minimized、Maximized 或 Hidden。
-Command
就如同在 Windows PowerShell 命令提示字元輸入一樣,執行指定的命令 (和任何參數),然後結束 (除非指定了 NoExit)。Command 的值可以是 "-"、字串或指令碼區塊。
如果 Command 的值是 "-",則會從標準輸入讀取命令文字。
請以大括號 ({}) 括住指令碼區塊。只有在 Windows PowerShell 中執行 PowerShell.exe 時,您才可以指定指令碼區塊。指令碼的結果會以還原序列化的 XML 物件 (而不是即時物件) 傳回父殼層。
如果 Command 的值是字串,Command 必須是命令中的最後參數,因為在命令之後輸入的任何字元都會被解譯為命令引數。
如果要撰寫執行 Windows PowerShell 命令的字串,請使用下列格式:
"& {<command>}"
其中引號代表字串,呼叫運算子 (&) 則會使命令執行。
-Help, -?, /?
顯示此訊息。如果您是在 Windows PowerShell 中輸入 PowerShell.exe 命令,命令參數之前要加上連字號 (-),而不是斜線 (/)。在 Cmd.exe 中,您可以使用連字號或是斜線。
範例
PowerShell -PSConsoleFile sqlsnapin.psc1
PowerShell -version 1.0 -NoLogo -InputFormat text -OutputFormat XML
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