

第 5 版 (V5) AWS Tools for PowerShell 已發行！

如需有關中斷變更和遷移應用程式的資訊，請參閱[遷移主題](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Tools for PowerShell V5 的 CodeDeploy 範例
<a name="powershell_codedeploy_code_examples"></a>

下列程式碼範例示範如何使用 AWS Tools for PowerShell V5 搭配 CodeDeploy 來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

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

以下程式碼範例顯示如何使用 `Add-CDOnPremiseInstanceTag`。

**Tools for PowerShell V5**  
**範例 1：此範例為指定的內部部署執行個體新增具有指定鍵與值的內部部署執行個體標籤。**  

```
Add-CDOnPremiseInstanceTag -InstanceName AssetTag12010298EX -Tag @{"Key" = "Name"; "Value" = "CodeDeployDemo-OnPrem"}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AddTagsToOnPremisesInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDApplication`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [GetApplication](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDApplicationBatch`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [BatchGetApplications](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDApplicationList`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得可用應用程式的清單。**  

```
Get-CDApplicationList
```
**輸出：**  

```
CodeDeployDemoApplication
CodePipelineDemoApplication
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListApplications](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDApplicationRevision`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [GetApplicationRevision](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDApplicationRevisionList`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [ListApplicationRevisions](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeployment`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [GetDeployment](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeploymentBatch`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [BatchGetDeployments](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeploymentConfig`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [GetDeploymentConfig](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeploymentConfigList`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得可用部署組態的清單。**  

```
Get-CDDeploymentConfigList
```
**輸出：**  

```
ThreeQuartersHealthy
CodeDeployDefault.OneAtATime
CodeDeployDefault.AllAtOnce
CodeDeployDefault.HalfAtATime
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListDeploymentConfigs](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeploymentGroup`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [GetDeploymentGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeploymentGroupList`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定之應用程式的部署群組清單。**  

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

```
ApplicationName              DeploymentGroups                                    NextToken
---------------              ----------------                                    ---------
CodeDeployDemoApplication    {CodeDeployDemoFleet, CodeDeployProductionFleet}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListDeploymentGroups](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeploymentInstance`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [GetDeploymentInstance](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeploymentInstanceList`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定之部署的執行個體 ID 清單。**  

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

```
i-254e22EX
i-274e22EX
i-3b4e22EX
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListDeploymentInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDDeploymentList`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定之應用程式和部署群組的部署 ID 清單。**  

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

```
d-QZMRGSTEX
d-RR0T5KTEX
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListDeployments](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDOnPremiseInstance`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [GetOnPremisesInstance](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDOnPremiseInstanceBatch`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [BatchGetOnPremisesInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CDOnPremiseInstanceList`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得可用的內部部署執行個體名稱的清單。**  

```
Get-CDOnPremiseInstanceList
```
**輸出：**  

```
AssetTag12010298EX
AssetTag12010298EX-2
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListOnPremisesInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-CDApplication`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立具有指定名稱的新應用程式。**  

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

```
f19e4b61-2231-4328-b0fd-e57f5EXAMPLE
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateApplication](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-CDDeployment`。

**Tools for PowerShell V5**  
**範例 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 執行個體標籤群組，以便將執行個體包含在藍/綠部署的替代環境中。**  

```
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 參考 (V5)》**中的 [CreateDeployment](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-CDDeploymentConfig`。

**Tools for PowerShell V5**  
**範例 1：此範例會利用指定的名稱和行為，建立新的部署組態。**  

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

```
0f3e8187-44ef-42da-aeed-b6823EXAMPLE
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateDeploymentConfig](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-CDDeploymentGroup`。

**Tools for PowerShell V5**  
**範例 1：此範例為指定的應用程式建立具有指定名稱的部署群組、Auto Scaling 群組、部署組態、標籤和服務角色。**  

```
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 執行個體標籤群組，以便將執行個體包含在藍/綠部署的替代環境中。**  

```
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 參考 (V5)》**中的 [CreateDeploymentGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Register-CDApplicationRevision`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [RegisterApplicationRevision](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Register-CDOnPremiseInstance`。

**Tools for PowerShell V5**  
**範例 1：此範例會使用指定的名稱和 IAM 使用者，註冊內部部署執行個體。**  

```
Register-CDOnPremiseInstance -IamUserArn arn:aws:iam::80398EXAMPLE:user/CodeDeployDemoUser -InstanceName AssetTag12010298EX
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RegisterOnPremisesInstance](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Remove-CDApplication`。

**Tools for PowerShell V5**  
**範例 1：此範例會刪除具有指定名稱的應用程式。繼續之前，此命令會先提示確認。新增 -Force 切換變數可刪除應用程式，無需提示。**  

```
Remove-CDApplication -ApplicationName MyNewApplication
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteApplication](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Remove-CDDeploymentConfig`。

**Tools for PowerShell V5**  
**範例 1：此範例會刪除具有指定名稱的部署組態。繼續之前，此命令會先提示確認。新增 -Force 切換變數可刪除部署組態，無需提示。**  

```
Remove-CDDeploymentConfig -DeploymentConfigName AtLeastTwoHealthyHosts
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteDeploymentConfig](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Remove-CDDeploymentGroup`。

**Tools for PowerShell V5**  
**範例 1：此範例為指定之應用程式刪除具有指定名稱的部署群組。繼續之前，此命令會先提示確認。新增 -Force 切換變數可刪除部署群組，無需提示。**  

```
Remove-CDDeploymentGroup -ApplicationName MyNewApplication -DeploymentGroupName MyNewDeploymentGroup
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [DeleteDeploymentGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Remove-CDOnPremiseInstanceTag`。

**Tools for PowerShell V5**  
**範例 1：此範例會刪除具有指定名稱之內部部署執行個體的指定標籤。繼續之前，此命令會先提示確認。新增 -Force 切換變數可刪除標籤，無需提示。**  

```
Remove-CDOnPremiseInstanceTag -InstanceName AssetTag12010298EX -Tag @{"Key" = "Name"; "Value" = "CodeDeployDemo-OnPrem"}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RemoveTagsFromOnPremisesInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Stop-CDDeployment`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [StopDeployment](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Unregister-CDOnPremiseInstance`。

**Tools for PowerShell V5**  
**範例 1：此範例使用指定的名稱取消註冊內部部署執行個體。**  

```
Unregister-CDOnPremiseInstance -InstanceName AssetTag12010298EX
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeregisterOnPremisesInstance](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Update-CDApplication`。

**Tools for PowerShell V5**  
**範例 1：此範例會變更指定的應用程式名稱。**  

```
Update-CDApplication -ApplicationName MyNewApplication -NewApplicationName MyNewApplication-2
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateApplication](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Update-CDDeploymentGroup`。

**Tools for PowerShell V5**  
**範例 1：此範例會變更指定應用程式之指定部署群組的名稱。**  

```
Update-CDDeploymentGroup -ApplicationName MyNewApplication -CurrentDeploymentGroupName MyNewDeploymentGroup -NewDeploymentGroupName MyNewDeploymentGroup-2
```
**範例 2：此範例示範如何指定執行個體必須識別的 EC2 執行個體標籤群組，以便將執行個體包含在藍/綠部署的替代環境中。**  

```
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 參考 (V5)》**中的 [UpdateDeploymentGroup](https://docs.aws.amazon.com/powershell/v5/reference)。