PowerShell 指令

動詞:powerShell

可用來源: <Standard>

執行以 Windows PowerShell 語言編寫的指令。

語法

powerShell [--handleerror(Boolean)] [--apartmentState(ApartmentState)] [--fromfile(Boolean)] --file(String) --script(String) (Boolean)=success (List<String>)=errors (List<String>)=warnings

輸入

Script 設計工具 必要 AcceptedTypes 說明
--handleerror 處理錯誤 選用項目 布林值 啟用後,如果在執行選定 Script 期間發生錯誤,則現行 Script 不會失敗,將在輸出中傳回發生的錯誤的相關資訊。 否則,如果發生錯誤,Script 將失敗。
--apartmentState 「執行緒」類型 選用項目 ApartmentState 必須在執行中使用的程序劃分形式,即 STAMTA
--fromfile 從檔案執行 選用項目 布林值 啟用後,將可以使用包含在檔案中的 PowerShell 指令執行 Script。
-- file 檔案 僅當「從檔案執行」為 True 時 文字 具有應執行的 Windows PowerShell 指令的檔案的完整目錄路徑和名稱。
--script Powershell Script 僅當「從檔案執行」為 False 時 文字 PowerShell 指令,稱為 cmdlet,使用 Windows PowerShell 語言。

輸出

Script 設計工具 AcceptedTypes 說明
成功 順利完成 布林值 如果成功執行了 PowerShell Script,則傳回 "True" ;否則,傳回 "False"。
errors 錯誤 清單<Text> 傳回因執行 PowerShell Script 而導致的錯誤清單。
warnings 警告 清單<Text> 傳回因執行 PowerShell Script 而導致的警告清單。

範例

執行 "get-Process" 指令取得在本端電腦上執行的處理程序,傳回其執行成功、錯誤和警告(如果有的話)。

defVar --name success --type Boolean
defVar --name errorList --type List --innertype String
defVar --name waningsList --type List --innertype String
powerShell --apartmentState "STA" --script "Get-Process" success=success errorList=errors waningsList=warnings
logMessage --message "Success: ${success}\r\nError: ${errorList}\r\nWarnings: ${waningsList}" --type "Info"
// Result: True
// Error: []
// Warnings: []

輸出值會根據在 Windows 裝置上執行 Script 的情況而有所不同。

另請參閱

  • 執行 DOS 指令
  • 執行 Windows Script