共用方式為


PowerShellOnTargetMachines@3 - 目的機器 v3 工作的 PowerShell

使用這項工作在遠端電腦上使用 PSSession 和Invoke-Command執行 PowerShell 腳本以進行遠端處理。

使用此工作在遠端電腦上執行 PowerShell 腳本, (s) 。 此版本的工作會使用 PSSession 和 Invoke-Command進行遠端處理。

Syntax

# PowerShell on target machines v3
# Execute PowerShell scripts on remote machines using PSSession and Invoke-Command for remoting.
- task: PowerShellOnTargetMachines@3
  inputs:
    Machines: # string. Required. Machines. 
    #UserName: # string. Username. 
    #UserPassword: # string. Password. 
  # Script options
    #ScriptType: 'Inline' # 'FilePath' | 'Inline'. Script Type. Default: Inline.
    #ScriptPath: # string. Required when ScriptType = FilePath. Script File Path. 
    InlineScript: # string. Required when ScriptType = Inline. Script. 
    #ScriptArguments: # string. Optional. Use when ScriptType = FilePath. Script Arguments. 
    #InitializationScript: # string. Optional. Use when ScriptType = FilePath. Initialization script. 
    #SessionVariables: # string. Optional. Use when ScriptType = FilePath. Session Variables. 
  # PSSession options
    #CommunicationProtocol: 'Https' # 'Http' | 'Https'. Protocol. Default: Https.
    #AuthenticationMechanism: 'Default' # 'Default' | 'Credssp'. Authentication. Default: Default.
    #NewPsSessionOptionArguments: '-SkipCACheck -IdleTimeout 7200000 -OperationTimeout 0 -OutputBufferingMode Block' # string. Session Option parameters. Default: -SkipCACheck -IdleTimeout 7200000 -OperationTimeout 0 -OutputBufferingMode Block.
  # Error handling options
    #ErrorActionPreference: 'stop' # 'stop' | 'continue' | 'silentlyContinue'. ErrorActionPreference. Default: stop.
    #failOnStderr: false # boolean. Fail on Standard Error. Default: false.
    #ignoreLASTEXITCODE: false # boolean. Ignore $LASTEXITCODE. Default: false.
  # Advanced
    #WorkingDirectory: # string. Working Directory. 
    #RunPowershellInParallel: true # boolean. Run PowerShell in Parallel. Default: true.
# PowerShell on Target Machines v3
# Execute PowerShell scripts on remote machine(s). This version of the task uses PSSession and Invoke-Command for remoting.
- task: PowerShellOnTargetMachines@3
  inputs:
    Machines: # string. Required. Machines. 
    #UserName: # string. Username. 
    #UserPassword: # string. Password. 
  # Script options
    #ScriptType: 'Inline' # 'FilePath' | 'Inline'. Script Type. Default: Inline.
    #ScriptPath: # string. Required when ScriptType = FilePath. Script File Path. 
    InlineScript: # string. Required when ScriptType = Inline. Script. 
    #ScriptArguments: # string. Optional. Use when ScriptType = FilePath. Script Arguments. 
    #InitializationScript: # string. Optional. Use when ScriptType = FilePath. Initialization script. 
    #SessionVariables: # string. Optional. Use when ScriptType = FilePath. Session Variables. 
  # PSSession options
    #CommunicationProtocol: 'Https' # 'Http' | 'Https'. Protocol. Default: Https.
    #AuthenticationMechanism: 'Default' # 'Default' | 'Credssp'. Authentication. Default: Default.
    #NewPsSessionOptionArguments: '-SkipCACheck -IdleTimeout 7200000 -OperationTimeout 0 -OutputBufferingMode Block' # string. Session Option parameters. Default: -SkipCACheck -IdleTimeout 7200000 -OperationTimeout 0 -OutputBufferingMode Block.
  # Error handling options
    #ErrorActionPreference: 'stop' # 'stop' | 'continue' | 'silentlyContinue'. ErrorActionPreference. Default: stop.
    #failOnStderr: false # boolean. Fail on Standard Error. Default: false.
    #ignoreLASTEXITCODE: false # boolean. Ignore $LASTEXITCODE. Default: false.
  # Advanced
    #WorkingDirectory: # string. Working Directory. 
    #RunPowershellInParallel: true # boolean. Run PowerShell in Parallel. Default: true.

輸入

Machines - 機器
string. 必要。

指定電腦 FQDN 或 IP 位址的逗號分隔清單,並選擇性地包含埠號碼。 可為以下項目:

  • Azure 資源群組的名稱。
  • 以逗號分隔的電腦名稱稱清單。 範例: dbserver.fabrikam.com,dbserver_int.fabrikam.com:5986,192.168.34:5986
  • 上一個工作的輸出變數。

如果您未指定埠,則會使用預設的 WinRM 埠。 這取決於您已設定的通訊協定。 針對 WinRM 2.0,預設 HTTP 埠為 5985 ,而預設 HTTPS 埠為 5986


UserName - 使用者
string.

指定目標主機上網域或本機系統管理帳戶的使用者名稱, (s) 。

  • 支援 、 domain\usernamemachine-name\username.\usernameusername 格式。
  • 不支援 UPN 格式,例如 username@domain.comNT Authority\System 和 內建系統帳戶。

UserPassword - 密碼
string.

指定目的電腦的密碼。 接受在組建/發行定義 $(passwordVariable) 中定義的變數。 您可以將變數類型標示為 secret 來保護它。


ScriptType - 腳本類型
string. 允許的值: FilePath (檔案路徑) , Inline 。 預設值:Inline

指定要執行的腳本類型:內嵌或檔案路徑。


ScriptPath - 腳本檔案路徑
string. 需要 。 ScriptType = FilePath

指定目的電腦上或 UNC 路徑上 PowerShell 腳本的位置,例如 C:\BudgetIT\Web\Deploy\Website.ps1 ,應該可從目的電腦存取。


InlineScript - 腳本
string. 需要 。 ScriptType = Inline 預設值:# Write your powershell commands here.\n\nWrite-Output "Hello World"


ScriptArguments - 腳本引數
string. 選擇性。 使用 時 ScriptType = FilePath

指定 PowerShell 腳本的引數。 可以是序數或具名參數,例如 -testParam test。 例如:-applicationPath $(applicationPath)-username $(vmusername)-password $(vmpassword)


InitializationScript - 初始化腳本
string. 選擇性。 使用 時 ScriptType = FilePath

指定目的機器或 UNC 路徑上 DSC 的資料腳本位置,例如 C:\BudgetIT\Web\Deploy\WebsiteConfiguration.ps1 。 建議您使用引數,而不是初始化腳本。


SessionVariables - 會話變數
string. 選擇性。 使用 時 ScriptType = FilePath

用來設定 PowerShell 腳本的會話變數。
指定逗號分隔清單,例如 $varx=valuex, $vary=valuey 。 最常用於與舊版發行服務的回溯相容性。 建議使用引數,而不是會話變數。


CommunicationProtocol - 協定
string. 允許值:HttpHttps。 預設值:Https

指定要用於與電腦 () 之 WinRM 服務連線的通訊協定。 預設值是 HTTPS


AuthenticationMechanism - 認證
string. 允許值:DefaultCredssp。 預設值:Default

指定用來建立 PSSession 的驗證機制。 若要 CredSSP 進行驗證,使用者名稱和密碼欄位是必要的。


NewPsSessionOptionArguments - 會話選項參數
string. 預設值:-SkipCACheck -IdleTimeout 7200000 -OperationTimeout 0 -OutputBufferingMode Block

遠端會話的進階選項 (New-PSSessionOption) 。 例如,、 -SkipCACheck-SkipCNCheck-SkipRevocationCheck 等。若要深入瞭解 ,請參閱所有會話選項的完整清單


ErrorActionPreference - ErrorActionPreference
string. 允許值:stopcontinuesilentlyContinue。 預設值:stop

在腳本頂端加上這一行 $ErrorActionPreference = 'VALUE'


failOnStderr - 標準錯誤失敗
boolean. 預設值:false

如果設定 true 為 ,則如果任何錯誤寫入錯誤管線,或將任何資料寫入標準錯誤資料流程,就會失敗。 否則,工作會依賴結束代碼來判斷失敗。


ignoreLASTEXITCODE - 忽略$LASTEXITCODE
boolean. 預設值:false

如果設定為 false ,則會在腳本結尾執行這一行 if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE } 。 這會導致外部命令的最後一個結束代碼傳播為 PowerShell 的結束代碼。 否則,此行不會執行到腳本結尾。


WorkingDirectory - 工作目錄
string.

指定執行腳本的工作目錄。


RunPowershellInParallel - 平行執行 PowerShell
boolean. 預設值:true

如果設定為 true ,請在目的電腦上平行執行 PowerShell 腳本。


工作控制項選項

除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制選項和一般工作屬性

輸出變數

無。

備註

使用此工作在遠端電腦上執行 PowerShell 腳本, (s) 。

這項工作可以同時執行 PowerShell 腳本和 PowerShell-DSC 腳本:

  • 針對 PowerShell 腳本,電腦必須已安裝 PowerShell 2.0 或更高版本。
  • 針對 PowerShell-DSC 腳本,電腦必須已安裝最新版本的 Windows Management Framework。 根據預設,這會安裝在 Windows 8.1、Windows Server 2012 R2 和後續版本上。

必要條件

此工作會使用 Windows 遠端系統管理 (WinRM) 來存取已加入網域或工作組的內部部署實體電腦或虛擬電腦。

設定內部部署實體電腦或虛擬機器的 WinRM

請遵循已加入網域中所述的步驟

設定適用于 Microsoft Azure 的 WinRM 虛擬機器

Azure 虛擬機器要求 WinRM 使用 HTTPS 通訊協定。 您可以使用自我簽署的測試憑證。 在此情況下,自動化代理程式將不會驗證憑證的真實性,因為該憑證是由受信任的憑證授權單位單位所簽發。

  • Azure 傳統虛擬機器。 當您從 Azure 入口網站 建立傳統虛擬機器時,虛擬機器已經設定為 WinRM over HTTPS,且已在防火牆中開啟預設埠 5986,並在電腦上安裝自我簽署憑證。 這些虛擬機器不需要進一步的設定即可存取。 您也可以使用 Azure 資源群組部署 工作來選取現有的傳統虛擬機器。

  • Azure 資源群組。 如果您已在Azure 入口網站中定義Azure 資源群組,則必須將其設定為使用 WinRM HTTPS 通訊協定。 您必須在防火牆中開啟埠 5986,並安裝自我簽署憑證。

若要動態部署包含虛擬機器的 Azure 資源群組,請使用 Azure 資源群組部署 工作。 此工作有一個名為 [啟用部署必要條件] 的核取方塊。 選取此選項可自動在虛擬機器上設定 WinRM HTTPS 通訊協定、在防火牆中開啟埠 5986,然後安裝測試憑證。 然後,虛擬機器就可以在部署工作中使用。

此工作版本的新功能

  • 使用 PSSession 和 invoke-command 在目的電腦上執行遠端處理。
  • 已新增內嵌腳本執行的支援。
  • 支援預設和 CredSSP 驗證。
  • 已新增錯誤處理的選項: ErrorActionPreferenceignoreLASTEXITCODE 和 [ 標準錯誤失敗]。

規格需求

需求 描述
管線類型 YAML、傳統組建、傳統版本
在 上執行 Agent、DeploymentGroup
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任意
可設定變數 任意
代理程式版本 2.134.0 或更新版本
工作類別 部署