PowerShellOnTargetMachines@3 - 대상 컴퓨터 v3 작업의 PowerShell

이 작업을 사용하여 원격 작업을 위해 PSSession 및 Invoke-Command 사용하여 원격 머신에서 PowerShell 스크립트를 실행합니다.

이 작업을 사용하여 원격 컴퓨터에서 PowerShell 스크립트를 실행합니다. 이 버전의 작업은 원격 작업에 PSSession 및 Invoke-Command 사용합니다.

구문

# 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.

대상 호스트의 도메인 또는 로컬 관리 계정의 사용자 이름을 지정합니다.

  • , , domain\usernamemachine-name\username.\username 와 같은 username형식이 지원됩니다.
  • 및 와 같은 username@domain.com 기본 제공 시스템 계정과 같은 NT Authority\System UPN 형식은 지원되지 않습니다.

UserPassword - 암호
string.

대상 머신의 암호를 지정합니다. 빌드/릴리스 정의에 정의된 변수는 $(passwordVariable) 허용됩니다. 변수 형식 secret 을 로 표시하여 보호할 수 있습니다.


ScriptType - 스크립트 유형
string. 허용되는 값: FilePath (파일 경로), Inline. 기본값은 Inline입니다.

실행할 스크립트의 형식을 인라인 또는 파일 경로로 지정합니다.


ScriptPath - 스크립트 파일 경로
string. 필요한 경우 ScriptType = FilePath입니다.

대상 컴퓨터 또는 UNC 경로(예 C:\BudgetIT\Web\Deploy\Website.ps1: )에서 대상 컴퓨터에서 액세스할 수 있는 PowerShell 스크립트의 위치를 지정합니다.


InlineScript - 스크립트
string. 필요한 경우 ScriptType = Inline입니다. 기본값은 # Write your powershell commands here.\n\nWrite-Output "Hello World"입니다.


ScriptArguments - 스크립트 인수
string. (선택 사항) 을 사용할 때 ScriptType = FilePath사용합니다.

PowerShell 스크립트의 인수를 지정합니다. 테스트와 같은 -testParam 서수 또는 명명된 매개 변수일 수 있습니다. 예: -applicationPath $(applicationPath), -username $(vmusername), -password $(vmpassword).


InitializationScript - 초기화 스크립트
string. 선택 사항입니다. 을 사용할 때 ScriptType = FilePath사용합니다.

대상 컴퓨터 또는 UNC 경로(예 C:\BudgetIT\Web\Deploy\WebsiteConfiguration.ps1: )에서 DSC에 대한 데이터 스크립트의 위치를 지정합니다. 초기화 스크립트 대신 인수를 사용하는 것이 좋습니다.


SessionVariables - 세션 변수
string. 선택 사항입니다. 을 사용할 때 ScriptType = FilePath사용합니다.

PowerShell 스크립트에 대한 세션 변수를 설정하는 데 사용됩니다.
와 같이 쉼표로 $varx=valuex, $vary=valuey구분된 목록을 지정합니다. 이전 버전의 릴리스 서비스와의 호환성을 위해 가장 일반적으로 사용됩니다. 세션 변수 대신 인수를 사용하는 것이 좋습니다.


CommunicationProtocol - 프로토콜
string. 허용되는 값: Http, Https. 기본값은 Https입니다.

컴퓨터와의 WinRM 서비스 연결에 사용할 프로토콜을 지정합니다. 기본값은 HTTPS입니다.


AuthenticationMechanism - 인증
string. 허용되는 값: Default, Credssp. 기본값은 Default입니다.

PSSession을 만드는 데 사용되는 인증 메커니즘을 지정합니다. 인증의 경우 CredSSP 사용자 이름 및 암호 필드는 필수입니다.


NewPsSessionOptionArguments - 세션 옵션 매개 변수
string. 기본값은 -SkipCACheck -IdleTimeout 7200000 -OperationTimeout 0 -OutputBufferingMode Block입니다.

원격 세션에 대한 고급 옵션(New-PSSessionOption). 예: -SkipCACheck, -SkipCNCheck, -SkipRevocationCheck, 등 자세한 내용은 모든 세션 옵션의 전체 목록을 참조하세요.


ErrorActionPreference - ErrorActionPreference
string. 허용되는 값: stop, continue, silentlyContinue. 기본값은 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 스크립트를 실행합니다.

이 작업은 PowerShell 스크립트와 PowerShell-DSC 스크립트를 모두 실행할 수 있습니다.

  • PowerShell 스크립트의 경우 컴퓨터에 PowerShell 2.0 이상이 설치되어 있어야 합니다.
  • PowerShell-DSC 스크립트의 경우 컴퓨터에 최신 버전의 Windows Management Framework 설치되어 있어야 합니다. 기본적으로 Windows 8.1, Windows Server 2012 R2 및 후속 버전에 설치됩니다.

필수 구성 요소

이 작업은 WinRM( Windows 원격 관리 )을 사용하여 도메인에 가입되거나 작업 그룹에 조인된 온-프레미스 물리적 컴퓨터 또는 가상 컴퓨터에 액세스합니다.

온-프레미스 물리적 컴퓨터 또는 가상 머신에 대해 WinRM을 설정하려면

도메인 가입에 설명된 단계를 따릅니다.

Microsoft Azure용 WinRM을 설정하려면 Virtual Machines

Azure Virtual Machines HTTPS 프로토콜을 사용하려면 WinRM이 필요합니다. 자체 서명된 테스트 인증서를 사용할 수 있습니다. 이 경우 자동화 에이전트는 신뢰할 수 있는 인증 기관에서 발급한 인증서의 신뢰성에 대한 유효성을 검사하지 않습니다.

  • Azure 클래식 Virtual Machines. Azure Portal 클래식 가상 머신을 만들 때 가상 머신은 이미 HTTPS를 통해 WinRM에 대해 설정되며, 기본 포트 5986이 방화벽에 이미 열려 있고 컴퓨터에 자체 서명된 인증서가 설치되어 있습니다. 이러한 가상 머신은 추가 구성 없이 액세스할 수 있습니다. 기존 클래식 가상 머신은 Azure 리소스 그룹 배포 작업을 사용하여 선택할 수도 있습니다.

  • Azure 리소스 그룹. azure 리소스 그룹이 이미 Azure Portal 정의된 경우 WinRM HTTPS 프로토콜을 사용하도록 구성해야 합니다. 방화벽에서 포트 5986을 열고 자체 서명된 인증서를 설치해야 합니다.

가상 머신을 포함하는 Azure 리소스 그룹을 동적으로 배포하려면 Azure 리소스 그룹 배포 작업을 사용합니다. 이 작업에는 배포 필수 구성 요소 사용 확인란이 있습니다. 가상 머신에서 WinRM HTTPS 프로토콜을 자동으로 설정하고, 방화벽에서 포트 5986을 열고, 테스트 인증서를 설치하려면 이 옵션을 선택합니다. 그런 다음, 가상 머신을 배포 작업에서 사용할 준비가 됩니다.

이 작업 버전의 새로운 기능

  • PSSession 및 invoke-command를 사용하여 대상 컴퓨터에서 원격 작업을 수행합니다.
  • 인라인 스크립트 실행에 대한 지원이 추가되었습니다.
  • 기본 및 CredSSP 인증이 지원됩니다.
  • 오류 처리에 대한 옵션이 추가되었습니다. ErrorActionPreference, ignoreLASTEXITCODE표준 오류 시 실패.

요구 사항

요구 사항 Description
파이프라인 유형 YAML, 클래식 빌드, 클래식 릴리스
실행 중 에이전트, DeploymentGroup
요청 없음
Capabilities 이 작업은 작업의 후속 작업에 대한 요구 사항을 충족하지 않습니다.
명령 제한 사항 모두
설정 가능한 변수 모두
에이전트 버전 2.134.0 이상
작업 범주 배포