

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# CodeDeploy 使用适用于 PowerShell V4 的工具的示例
<a name="powershell_4_codedeploy_code_examples"></a>

以下代码示例向您展示了如何使用带 CodeDeploy的 AWS Tools for PowerShell V4 来执行操作和实现常见场景。

*操作*是大型程序的代码摘录，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `Add-CDOnPremiseInstanceTag`
<a name="codedeploy_AddTagsToOnPremisesInstances_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Add-CDOnPremiseInstanceTag`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例为指定的本地实例添加具有指定键和值的本地实例标签。**  

```
Add-CDOnPremiseInstanceTag -InstanceName AssetTag12010298EX -Tag @{"Key" = "Name"; "Value" = "CodeDeployDemo-OnPrem"}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [AddTagsToOnPremisesInstances](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDApplication`
<a name="codedeploy_GetApplication_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDApplication`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定应用程序的信息。**  

```
Get-CDApplication -ApplicationName CodeDeployDemoApplication
```
**输出**：  

```
ApplicationId                           ApplicationName              CreateTime              LinkedToGitHub
-------------                           ---------------              ----------              --------------
e07fb938-091e-4f2f-8963-4d3e8EXAMPLE    CodeDeployDemoApplication    7/20/2015 9:49:48 PM    False
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetApplication](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDApplicationBatch`
<a name="codedeploy_BatchGetApplications_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDApplicationBatch`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定应用程序的信息。**  

```
Get-CDApplicationBatch -ApplicationName CodeDeployDemoApplication, CodePipelineDemoApplication
```
**输出**：  

```
ApplicationId                           ApplicationName              CreateTime              LinkedToGitHub
-------------                           ---------------              ----------              --------------
e07fb938-091e-4f2f-8963-4d3e8EXAMPLE    CodeDeployDemoApplication    7/20/2015 9:49:48 PM    False
1ecfd602-62f1-4038-8f0d-06688EXAMPLE    CodePipelineDemoApplication  8/13/2015 5:53:26 PM    False
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [BatchGetApplications](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDApplicationList`
<a name="codedeploy_ListApplications_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDApplicationList`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取可用应用程序的列表。**  

```
Get-CDApplicationList
```
**输出**：  

```
CodeDeployDemoApplication
CodePipelineDemoApplication
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListApplications](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDApplicationRevision`
<a name="codedeploy_GetApplicationRevision_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDApplicationRevision`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定应用程序版本的信息。**  

```
$revision = Get-CDApplicationRevision -ApplicationName CodeDeployDemoApplication -S3Location_Bucket amzn-s3-demo-bucket -Revision_RevisionType S3 -S3Location_Key 5xd27EX.zip -S3Location_BundleType zip -S3Location_ETag 4565c1ac97187f190c1a90265EXAMPLE
Write-Output ("Description = " + $revision.RevisionInfo.Description + ", RegisterTime = " + $revision.RevisionInfo.RegisterTime)
```
**输出**：  

```
Description = Application revision registered by Deployment ID: d-CX9CHN3EX, RegisterTime = 07/20/2015 23:46:42
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetApplicationRevision](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDApplicationRevisionList`
<a name="codedeploy_ListApplicationRevisions_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDApplicationRevisionList`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定应用程序的可用修订版的信息。**  

```
ForEach ($revision in (Get-CDApplicationRevisionList -ApplicationName CodeDeployDemoApplication -Deployed Ignore)) {
>>   If ($revision.RevisionType -Eq "S3") {
>>     Write-Output ("Type = S3, Bucket = " + $revision.S3Location.Bucket + ", BundleType = " + $revision.S3Location.BundleType + ", ETag = " + $revision.S3Location.ETag + ", Key = " + $revision.S3Location.Key)
>>   }
>>   If ($revision.RevisionType -Eq "GitHub") {
>>     Write-Output ("Type = GitHub, CommitId = " + $revision.GitHubLocation.CommitId + ", Repository = " + $revision.GitHubLocation.Repository)
>>   }
>> }
>>
```
**输出**：  

```
Type = S3, Bucket = amzn-s3-demo-bucket, BundleType = zip, ETag = 4565c1ac97187f190c1a90265EXAMPLE, Key = 5xd27EX.zip
Type = GitHub, CommitId = f48933c3...76405362, Repository = MyGitHubUser/CodeDeployDemoRepo
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListApplicationRevisions](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeployment`
<a name="codedeploy_GetDeployment_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeployment`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定部署的摘要信息。**  

```
Get-CDDeployment -DeploymentId d-QZMRGSTEX
```
**输出**：  

```
ApplicationName               : CodeDeployDemoApplication
CompleteTime                  : 7/23/2015 11:26:04 PM
CreateTime                    : 7/23/2015 11:24:43 PM
Creator                       : user
DeploymentConfigName          : CodeDeployDefault.OneAtATime
DeploymentGroupName           : CodeDeployDemoFleet
DeploymentId                  : d-QZMRGSTEX
DeploymentOverview            : Amazon.CodeDeploy.Model.DeploymentOverview
Description                   :
ErrorInformation              :
IgnoreApplicationStopFailures : False
Revision                      : Amazon.CodeDeploy.Model.RevisionLocation
StartTime                     : 1/1/0001 12:00:00 AM
Status                        : Succeeded
```
**示例 2：此示例获取有关参与指定部署的实例的状态信息。**  

```
(Get-CDDeployment -DeploymentId d-QZMRGSTEX).DeploymentOverview
```
**输出**：  

```
Failed     : 0
InProgress : 0
Pending    : 0
Skipped    : 0
Succeeded  : 3
```
**示例 3：此示例获取有关指定部署的应用程序修订版的信息。**  

```
(Get-CDDeployment -DeploymentId d-QZMRGSTEX).Revision.S3Location
```
**输出**：  

```
Bucket     : amzn-s3-demo-bucket
BundleType : zip
ETag       : cfbb81b304ee5e27efc21adaed3EXAMPLE
Key        : clzfqEX
Version    :
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetDeployment](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeploymentBatch`
<a name="codedeploy_BatchGetDeployments_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeploymentBatch`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定部署的信息。**  

```
Get-CDDeploymentBatch -DeploymentId d-QZMRGSTEX, d-RR0T5KTEX
```
**输出**：  

```
ApplicationName               : CodeDeployDemoApplication
CompleteTime                  : 7/23/2015 11:26:04 PM
CreateTime                    : 7/23/2015 11:24:43 PM
Creator                       : user
DeploymentConfigName          : CodeDeployDefault.OneAtATime
DeploymentGroupName           : CodeDeployDemoFleet
DeploymentId                  : d-QZMRGSTEX
DeploymentOverview            : Amazon.CodeDeploy.Model.DeploymentOverview
Description                   :
ErrorInformation              :
IgnoreApplicationStopFailures : False
Revision                      : Amazon.CodeDeploy.Model.RevisionLocation
StartTime                     : 1/1/0001 12:00:00 AM
Status                        : Succeeded

ApplicationName               : CodePipelineDemoApplication
CompleteTime                  : 7/23/2015 6:07:30 PM
CreateTime                    : 7/23/2015 6:06:29 PM
Creator                       : user
DeploymentConfigName          : CodeDeployDefault.OneAtATime
DeploymentGroupName           : CodePipelineDemoFleet
DeploymentId                  : d-RR0T5KTEX
DeploymentOverview            : Amazon.CodeDeploy.Model.DeploymentOverview
Description                   :
ErrorInformation              :
IgnoreApplicationStopFailures : False
Revision                      : Amazon.CodeDeploy.Model.RevisionLocation
StartTime                     : 1/1/0001 12:00:00 AM
Status                        : Succeeded
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [BatchGetDeployments](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeploymentConfig`
<a name="codedeploy_GetDeploymentConfig_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeploymentConfig`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定部署配置的摘要信息。**  

```
Get-CDDeploymentConfig -DeploymentConfigName ThreeQuartersHealthy
```
**输出**：  

```
CreateTime              DeploymentConfigId                      DeploymentConfigName    MinimumHealthyHosts
----------              ------------------                      --------------------    -------------------
10/3/2014 4:32:30 PM    518a3950-d034-46a1-9d2c-3c949EXAMPLE    ThreeQuartersHealthy    Amazon.CodeDeploy.Model.MinimumHealthyHosts
```
**示例 2：此示例获取有关指定部署配置的定义的信息。**  

```
Write-Output ((Get-CDDeploymentConfig -DeploymentConfigName ThreeQuartersHealthy).MinimumHealthyHosts)
```
**输出**：  

```
Type             Value
----             -----
FLEET_PERCENT    75
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetDeploymentConfig](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeploymentConfigList`
<a name="codedeploy_ListDeploymentConfigs_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeploymentConfigList`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取可用部署配置的列表。**  

```
Get-CDDeploymentConfigList
```
**输出**：  

```
ThreeQuartersHealthy
CodeDeployDefault.OneAtATime
CodeDeployDefault.AllAtOnce
CodeDeployDefault.HalfAtATime
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListDeploymentConfigs](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeploymentGroup`
<a name="codedeploy_GetDeploymentGroup_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeploymentGroup`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定部署组的信息。**  

```
Get-CDDeploymentGroup -ApplicationName CodeDeployDemoApplication -DeploymentGroupName CodeDeployDemoFleet
```
**输出**：  

```
ApplicationName              : CodeDeployDemoApplication
AutoScalingGroups            : {}
DeploymentConfigName         : CodeDeployDefault.OneAtATime
DeploymentGroupId            : 7d7c098a-b444-4b27-96ef-22791EXAMPLE
DeploymentGroupName          : CodeDeployDemoFleet
Ec2TagFilters                : {Name}
OnPremisesInstanceTagFilters : {}
ServiceRoleArn               : arn:aws:iam::80398EXAMPLE:role/CodeDeploySampleStack-4ph6EX-CodeDeployTrustRole-O9MWP7XTL8EX
TargetRevision               : Amazon.CodeDeploy.Model.RevisionLocation
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetDeploymentGroup](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeploymentGroupList`
<a name="codedeploy_ListDeploymentGroups_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeploymentGroupList`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取指定应用程序的部署组的列表。**  

```
Get-CDDeploymentGroupList -ApplicationName CodeDeployDemoApplication
```
**输出**：  

```
ApplicationName              DeploymentGroups                                    NextToken
---------------              ----------------                                    ---------
CodeDeployDemoApplication    {CodeDeployDemoFleet, CodeDeployProductionFleet}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListDeploymentGroups](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeploymentInstance`
<a name="codedeploy_GetDeploymentInstance_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeploymentInstance`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定部署的指定实例的信息。**  

```
Get-CDDeploymentInstance -DeploymentId d-QZMRGSTEX -InstanceId i-254e22EX
```
**输出**：  

```
DeploymentId    : d-QZMRGSTEX
InstanceId      : arn:aws:ec2:us-east-1:80398EXAMPLE:instance/i-254e22EX
LastUpdatedAt   : 7/23/2015 11:25:24 PM
LifecycleEvents : {ApplicationStop, DownloadBundle, BeforeInstall, Install...}
Status          : Succeeded
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetDeploymentInstance](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeploymentInstanceList`
<a name="codedeploy_ListDeploymentInstances_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeploymentInstanceList`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取指定部署 IDs 的实例列表。**  

```
Get-CDDeploymentInstanceList -DeploymentId d-QZMRGSTEX
```
**输出**：  

```
i-254e22EX
i-274e22EX
i-3b4e22EX
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListDeploymentInstances](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDDeploymentList`
<a name="codedeploy_ListDeployments_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDDeploymentList`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取指定应用程序和部署 IDs 组的部署列表。**  

```
Get-CDDeploymentList -ApplicationName CodeDeployDemoApplication -DeploymentGroupName CodeDeployDemoFleet
```
**输出**：  

```
d-QZMRGSTEX
d-RR0T5KTEX
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListDeployments](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDOnPremiseInstance`
<a name="codedeploy_GetOnPremisesInstance_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDOnPremiseInstance`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定本地实例的信息。**  

```
Get-CDOnPremiseInstance -InstanceName AssetTag12010298EX
```
**输出**：  

```
DeregisterTime : 1/1/0001 12:00:00 AM
IamUserArn     : arn:aws:iam::80398EXAMPLE:user/CodeDeployDemoUser
InstanceArn    : arn:aws:codedeploy:us-east-1:80398EXAMPLE:instance/AssetTag12010298EX_rDH556dxEX
InstanceName   : AssetTag12010298EX
RegisterTime   : 4/3/2015 6:36:24 PM
Tags           : {Name}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetOnPremisesInstance](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDOnPremiseInstanceBatch`
<a name="codedeploy_BatchGetOnPremisesInstances_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDOnPremiseInstanceBatch`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关指定本地实例的信息。**  

```
Get-CDOnPremiseInstanceBatch -InstanceName AssetTag12010298EX, AssetTag12010298EX-2
```
**输出**：  

```
DeregisterTime : 1/1/0001 12:00:00 AM
IamUserArn     : arn:aws:iam::80398EXAMPLE:user/CodeDeployFRWUser
InstanceArn    : arn:aws:codedeploy:us-east-1:80398EXAMPLE:instance/AssetTag12010298EX-2_XmeSz18rEX
InstanceName   : AssetTag12010298EX-2
RegisterTime   : 4/3/2015 6:38:52 PM
Tags           : {Name}

DeregisterTime : 1/1/0001 12:00:00 AM
IamUserArn     : arn:aws:iam::80398EXAMPLE:user/CodeDeployDemoUser
InstanceArn    : arn:aws:codedeploy:us-east-1:80398EXAMPLE:instance/AssetTag12010298EX_rDH556dxEX
InstanceName   : AssetTag12010298EX
RegisterTime   : 4/3/2015 6:36:24 PM
Tags           : {Name}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [BatchGetOnPremisesInstances](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-CDOnPremiseInstanceList`
<a name="codedeploy_ListOnPremisesInstances_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Get-CDOnPremiseInstanceList`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取可用本地实例名称的列表。**  

```
Get-CDOnPremiseInstanceList
```
**输出**：  

```
AssetTag12010298EX
AssetTag12010298EX-2
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListOnPremisesInstances](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `New-CDApplication`
<a name="codedeploy_CreateApplication_powershell_4_topic"></a>

以下代码示例演示了如何使用 `New-CDApplication`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用指定名称创建新的应用程序。**  

```
New-CDApplication -ApplicationName MyNewApplication
```
**输出**：  

```
f19e4b61-2231-4328-b0fd-e57f5EXAMPLE
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateApplication](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `New-CDDeployment`
<a name="codedeploy_CreateDeployment_powershell_4_topic"></a>

以下代码示例演示了如何使用 `New-CDDeployment`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用指定的部署配置和应用程序修订版为指定的应用程序和部署组创建新部署。**  

```
New-CDDeployment -ApplicationName MyNewApplication -S3Location_Bucket amzn-s3-demo-bucket -S3Location_BundleType zip -DeploymentConfigName CodeDeployDefault.OneAtATime -DeploymentGroupName MyNewDeploymentGroup -IgnoreApplicationStopFailures $True -S3Location_Key aws-codedeploy_linux-master.zip -RevisionType S3
```
**输出**：  

```
d-ZHROG7UEX
```
**示例 2：此示例说明如何指定一组 EC2 实例标签，实例必须通过这些标签进行标识，才能将其包含在 blue/green 部署的替换环境中。**  

```
New-CDDeployment -ApplicationName MyNewApplication -S3Location_Bucket amzn-s3-demo-bucket -S3Location_BundleType zip -DeploymentConfigName CodeDeployDefault.OneAtATime -DeploymentGroupName MyNewDeploymentGroup -IgnoreApplicationStopFailures $True -S3Location_Key aws-codedeploy_linux-master.zip -RevisionType S3 -Ec2TagSetList @(@{Key="key1";Type="KEY_ONLY"},@{Key="Key2";Type="KEY_AND_VALUE";Value="Value2"}),@(@{Key="Key3";Type="VALUE_ONLY";Value="Value3"})
```
**输出**：  

```
d-ZHROG7UEX
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateDeployment](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `New-CDDeploymentConfig`
<a name="codedeploy_CreateDeploymentConfig_powershell_4_topic"></a>

以下代码示例演示了如何使用 `New-CDDeploymentConfig`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用指定的名称和行为创建新的部署配置。**  

```
New-CDDeploymentConfig -DeploymentConfigName AtLeastTwoHealthyHosts -MinimumHealthyHosts_Type HOST_COUNT -MinimumHealthyHosts_Value 2
```
**输出**：  

```
0f3e8187-44ef-42da-aeed-b6823EXAMPLE
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateDeploymentConfig](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `New-CDDeploymentGroup`
<a name="codedeploy_CreateDeploymentGroup_powershell_4_topic"></a>

以下代码示例演示了如何使用 `New-CDDeploymentGroup`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例为指定的应用程序创建具有指定名称、自动扩缩组、部署配置、标签和服务角色的部署组。**  

```
New-CDDeploymentGroup -ApplicationName MyNewApplication -AutoScalingGroup CodeDeployDemo-ASG -DeploymentConfigName CodeDeployDefault.OneAtATime -DeploymentGroupName MyNewDeploymentGroup -Ec2TagFilter @{Key="Name"; Type="KEY_AND_VALUE"; Value="CodeDeployDemo"} -ServiceRoleArn arn:aws:iam::80398EXAMPLE:role/CodeDeployDemo
```
**输出**：  

```
16bbf199-95fd-40fc-a909-0bbcfEXAMPLE
```
**示例 2：此示例说明如何指定一组 EC2 实例标签，实例必须通过这些标签进行标识，才能将其包含在 blue/green 部署的替换环境中。**  

```
New-CDDeploymentGroup -ApplicationName MyNewApplication -AutoScalingGroup CodeDeployDemo-ASG -DeploymentConfigName CodeDeployDefault.OneAtATime -DeploymentGroupName MyNewDeploymentGroup -Ec2TagFilter @{Key="Name"; Type="KEY_AND_VALUE"; Value="CodeDeployDemo"} -ServiceRoleArn arn:aws:iam::80398EXAMPLE:role/CodeDeployDemo -Ec2TagSetList @(@{Key="key1";Type="KEY_ONLY"},@{Key="Key2";Type="KEY_AND_VALUE";Value="Value2"}),@(@{Key="Key3";Type="VALUE_ONLY";Value="Value3"})
```
**输出**：  

```
16bbf199-95fd-40fc-a909-0bbcfEXAMPLE
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateDeploymentGroup](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Register-CDApplicationRevision`
<a name="codedeploy_RegisterApplicationRevision_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Register-CDApplicationRevision`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例在指定的 Amazon S3 位置为指定的应用程序注册应用程序修订版。**  

```
Register-CDApplicationRevision -ApplicationName MyNewApplication -S3Location_Bucket amzn-s3-demo-bucket -S3Location_BundleType zip -S3Location_Key aws-codedeploy_linux-master.zip -Revision_RevisionType S3
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [RegisterApplicationRevision](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Register-CDOnPremiseInstance`
<a name="codedeploy_RegisterOnPremisesInstance_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Register-CDOnPremiseInstance`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用指定的名称和 IAM 用户注册本地实例。**  

```
Register-CDOnPremiseInstance -IamUserArn arn:aws:iam::80398EXAMPLE:user/CodeDeployDemoUser -InstanceName AssetTag12010298EX
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [RegisterOnPremisesInstance](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Remove-CDApplication`
<a name="codedeploy_DeleteApplication_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Remove-CDApplication`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除具有指定名称的应用程序。在继续操作之前，该命令将提示进行确认。添加 -Force 参数可在不提示的情况下删除应用程序。**  

```
Remove-CDApplication -ApplicationName MyNewApplication
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeleteApplication](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Remove-CDDeploymentConfig`
<a name="codedeploy_DeleteDeploymentConfig_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Remove-CDDeploymentConfig`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除具有指定名称的部署配置。在继续操作之前，该命令将提示进行确认。添加 -Force 参数可在不提示的情况下删除部署配置。**  

```
Remove-CDDeploymentConfig -DeploymentConfigName AtLeastTwoHealthyHosts
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeleteDeploymentConfig](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Remove-CDDeploymentGroup`
<a name="codedeploy_DeleteDeploymentGroup_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Remove-CDDeploymentGroup`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除指定应用程序的具有指定名称的部署组。在继续操作之前，该命令将提示进行确认。添加 -Force 参数可在不提示的情况下删除部署组。**  

```
Remove-CDDeploymentGroup -ApplicationName MyNewApplication -DeploymentGroupName MyNewDeploymentGroup
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeleteDeploymentGroup](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Remove-CDOnPremiseInstanceTag`
<a name="codedeploy_RemoveTagsFromOnPremisesInstances_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Remove-CDOnPremiseInstanceTag`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例为具有指定名称的本地实例删除指定的标签。在继续操作之前，该命令将提示进行确认。添加 -Force 参数可在不提示的情况下删除标签。**  

```
Remove-CDOnPremiseInstanceTag -InstanceName AssetTag12010298EX -Tag @{"Key" = "Name"; "Value" = "CodeDeployDemo-OnPrem"}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [RemoveTagsFromOnPremisesInstances](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Stop-CDDeployment`
<a name="codedeploy_StopDeployment_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Stop-CDDeployment`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例尝试停止具有指定部署 ID 的部署。**  

```
Stop-CDDeployment -DeploymentId d-LJQNREYEX
```
**输出**：  

```
Status     StatusMessage
------     -------------
Pending    Stopping Pending. Stopping to schedule commands in the deployment instances
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [StopDeployment](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Unregister-CDOnPremiseInstance`
<a name="codedeploy_DeregisterOnPremisesInstance_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Unregister-CDOnPremiseInstance`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例取消注册具有指定名称的本地实例。**  

```
Unregister-CDOnPremiseInstance -InstanceName AssetTag12010298EX
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeregisterOnPremisesInstance](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Update-CDApplication`
<a name="codedeploy_UpdateApplication_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Update-CDApplication`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例更改指定应用程序的名称。**  

```
Update-CDApplication -ApplicationName MyNewApplication -NewApplicationName MyNewApplication-2
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [UpdateApplication](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Update-CDDeploymentGroup`
<a name="codedeploy_UpdateDeploymentGroup_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Update-CDDeploymentGroup`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例更改指定应用程序的指定部署组的名称。**  

```
Update-CDDeploymentGroup -ApplicationName MyNewApplication -CurrentDeploymentGroupName MyNewDeploymentGroup -NewDeploymentGroupName MyNewDeploymentGroup-2
```
**示例 2：此示例说明如何指定一组 EC2 实例标签，实例必须通过这些标签进行标识，才能将其包含在 blue/green 部署的替换环境中。**  

```
Update-CDDeploymentGroup -ApplicationName MyNewApplication -CurrentDeploymentGroupName MyNewDeploymentGroup -NewDeploymentGroupName MyNewDeploymentGroup-2 -Ec2TagSetList @(@{Key="key1";Type="KEY_ONLY"},@{Key="Key2";Type="KEY_AND_VALUE";Value="Value2"}),@(@{Key="Key3";Type="VALUE_ONLY";Value="Value3"})
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [UpdateDeploymentGroup](https://docs.aws.amazon.com/powershell/v4/reference)中的。