

第 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 的 Auto Scaling 範例
<a name="powershell_auto-scaling_code_examples"></a>

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

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

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

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

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

### `Add-ASLoadBalancer`
<a name="auto-scaling_AttachLoadBalancers_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的負載平衡器連接至指定的 Auto Scaling 群組。**  

```
Add-ASLoadBalancer -LoadBalancerName my-lb -AutoScalingGroupName my-asg
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AttachLoadBalancers](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Complete-ASLifecycleAction`
<a name="auto-scaling_CompleteLifecycleAction_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會完成指定的生命週期動作。**  

```
Complete-ASLifecycleAction -LifecycleHookName myLifecycleHook -AutoScalingGroupName my-asg -LifecycleActionResult CONTINUE -LifecycleActionToken bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [CompleteLifecycleAction](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Disable-ASMetricsCollection`
<a name="auto-scaling_DisableMetricsCollection_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例停用指定的 Auto Scaling 群組的指定指標監控功能。**  

```
Disable-ASMetricsCollection -AutoScalingGroupName my-asg -Metric @("GroupMinSize", "GroupMaxSize")
```
**範例 2：此範例停用指定的 Auto Scaling 群組的所有指標監控功能。**  

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

### `Dismount-ASInstance`
<a name="auto-scaling_DetachInstances_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的執行個體與指定的 Auto Scaling 群組分開，並減少所需的容量，如此 Auto Scaling 就不會啟動替代執行個體。**  

```
Dismount-ASInstance -InstanceId i-93633f9b -AutoScalingGroupName my-asg -ShouldDecrementDesiredCapacity $true
```
**輸出：**  

```
ActivityId           : 06733445-ce94-4039-be1b-b9f1866e276e
AutoScalingGroupName : my-asg
Cause                : At 2015-11-20T22:34:59Z instance i-93633f9b was detached in response to a user request, shrinking
                       the capacity from 2 to 1.
Description          : Detaching EC2 instance: i-93633f9b
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 
Progress             : 50
StartTime            : 11/20/2015 2:34:59 PM
StatusCode           : InProgress
StatusMessage        :
```
**範例 2：此範例將指定的執行個體與指定的 Auto Scaling 群組分開，而不會減少所需的容量。Auto Scaling 會啟動替代執行個體。**  

```
Dismount-ASInstance -InstanceId i-7bf746a2 -AutoScalingGroupName my-asg -ShouldDecrementDesiredCapacity $false
```
**輸出：**  

```
ActivityId           : f43a3cd4-d38c-4af7-9fe0-d76ec2307b6d
AutoScalingGroupName : my-asg
Cause                : At 2015-11-20T22:34:59Z instance i-7bf746a2 was detached in response to a user request.
Description          : Detaching EC2 instance: i-7bf746a2
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 
Progress             : 50
StartTime            : 11/20/2015 2:34:59 PM
StatusCode           : InProgress
StatusMessage        :
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [DetachInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Dismount-ASLoadBalancer`
<a name="auto-scaling_DetachLoadBalancers_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的負載平衡器與指定的 Auto Scaling 群組分開。**  

```
Dismount-ASLoadBalancer -LoadBalancerName my-lb -AutoScalingGroupName my-asg
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [DetachLoadBalancers](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Enable-ASMetricsCollection`
<a name="auto-scaling_EnableMetricsCollection_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例啟用指定的 Auto Scaling 群組的指定指標監控功能。**  

```
Enable-ASMetricsCollection  -Metric @("GroupMinSize", "GroupMaxSize") -AutoScalingGroupName my-asg -Granularity 1Minute
```
**範例 2：此範例監控指定的 Auto Scaling 群組的所有指標監控功能。**  

```
Enable-ASMetricsCollection -AutoScalingGroupName my-asg -Granularity 1Minute
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [EnableMetricsCollection](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Enter-ASStandby`
<a name="auto-scaling_EnterStandby_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的執行個體置於待命模式，並減少所需的容量，如此 Auto Scaling 就不會啟動替代執行個體。**  

```
Enter-ASStandby -InstanceId i-93633f9b -AutoScalingGroupName my-asg -ShouldDecrementDesiredCapacity $true
```
**輸出：**  

```
ActivityId           : e36a5a54-ced6-4df8-bd19-708e2a59a649
AutoScalingGroupName : my-asg
Cause                : At 2015-11-22T15:48:06Z instance i-95b8484f was moved to standby in response to a user request,
                       shrinking the capacity from 2 to 1.
Description          : Moving EC2 instance to Standby: i-95b8484f
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 
Progress             : 50
StartTime            : 11/22/2015 7:48:06 AM
StatusCode           : InProgress
StatusMessage        :
```
**範例 2：此範例將指定的執行個體置於待命模式，而不會減少所需的容量。Auto Scaling 會啟動替代執行個體。**  

```
Enter-ASStandby -InstanceId i-93633f9b -AutoScalingGroupName my-asg -ShouldDecrementDesiredCapacity $false
```
**輸出：**  

```
ActivityId           : e36a5a54-ced6-4df8-bd19-708e2a59a649
AutoScalingGroupName : my-asg
Cause                : At 2015-11-22T15:48:06Z instance i-95b8484f was moved to standby in response to a user request.
Description          : Moving EC2 instance to Standby: i-95b8484f
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 
Progress             : 50
StartTime            : 11/22/2015 7:48:06 AM
StatusCode           : InProgress
StatusMessage        :
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [EnterStandby](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Exit-ASStandby`
<a name="auto-scaling_ExitStandby_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的執行個體移出待命模式。**  

```
Exit-ASStandby -InstanceId i-93633f9b -AutoScalingGroupName my-asg
```
**輸出：**  

```
ActivityId           : 1833d3e8-e32f-454e-b731-0670ad4c6934
AutoScalingGroupName : my-asg
Cause                : At 2015-11-22T15:51:21Z instance i-95b8484f was moved out of standby in response to a user 
                       request, increasing the capacity from 1 to 2.
Description          : Moving EC2 instance out of Standby: i-95b8484f
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 
Progress             : 30
StartTime            : 11/22/2015 7:51:21 AM
StatusCode           : PreInService
StatusMessage        :
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [ExitStandby](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-ASAccountLimit`
<a name="auto-scaling_DescribeAccountLimits_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例說明您 AWS 帳戶的 Auto Scaling 資源限制。**  

```
Get-ASAccountLimit
```
**輸出：**  

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

### `Get-ASAdjustmentType`
<a name="auto-scaling_DescribeAdjustmentTypes_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例描述 Auto Scaling 支援的調整類型。**  

```
Get-ASAdjustmentType
```
**輸出：**  

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

### `Get-ASAutoScalingGroup`
<a name="auto-scaling_DescribeAutoScalingGroups_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例列出 Auto Scaling 群組的名稱。**  

```
Get-ASAutoScalingGroup | format-table -property AutoScalingGroupName
```
**輸出：**  

```
AutoScalingGroupName
--------------------
my-asg-1
my-asg-2
my-asg-3
my-asg-4
my-asg-5
my-asg-6
```
**範例 2：此範例描述指定的 Auto Scaling 群組。**  

```
Get-ASAutoScalingGroup -AutoScalingGroupName my-asg-1
```
**輸出：**  

```
AutoScalingGroupARN     : arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:930d940e-891e-4781-a11a-7b0acd480
                          f03:autoScalingGroupName/my-asg-1
AutoScalingGroupName    : my-asg-1
AvailabilityZones       : {us-west-2b, us-west-2a}
CreatedTime             : 3/1/2015 9:05:31 AM
DefaultCooldown         : 300
DesiredCapacity         : 2
EnabledMetrics          : {}
HealthCheckGracePeriod  : 300
HealthCheckType         : EC2
Instances               : {my-lc}
LaunchConfigurationName : my-lc
LoadBalancerNames       : {}
MaxSize                 : 0
MinSize                 : 0
PlacementGroup          :
Status                  :
SuspendedProcesses      : {}
Tags                    : {}
TerminationPolicies     : {Default}
VPCZoneIdentifier       : subnet-e4f33493,subnet-5264e837
```
**範例 3：此範例描述指定的兩個 Auto Scaling 群組。**  

```
Get-ASAutoScalingGroup -AutoScalingGroupName @("my-asg-1", "my-asg-2")
```
**範例 4：此範例描述指定之 Auto Scaling 群組的 Auto Scaling 執行個體。**  

```
(Get-ASAutoScalingGroup -AutoScalingGroupName my-asg-1).Instances
```
**範例 5：此範例描述所有 Auto Scaling 群組。**  

```
Get-ASAutoScalingGroup
```
**範例 6：此範例描述指定的 Auto Scaling 群組的 LaunchTemplate。此範例假設「執行個體購買選項」設定為「依循啟動範本」。如果此選項設定為「結合購買選項和執行個體類型」，則可使用 "MixedInstancesPolicy.LaunchTemplate" 屬性存取 LaunchTemplate。**  

```
(Get-ASAutoScalingGroup -AutoScalingGroupName my-ag-1).LaunchTemplate
```
**輸出：**  

```
LaunchTemplateId     LaunchTemplateName   Version
----------------     ------------------   -------
lt-06095fd619cb40371 test-launch-template $Default
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeAutoScalingGroups](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-ASAutoScalingInstance`
<a name="auto-scaling_DescribeAutoScalingInstances_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例列出 Auto Scaling 執行個體的 ID。**  

```
Get-ASAutoScalingInstance | format-table -property InstanceId
```
**輸出：**  

```
InstanceId
----------
i-12345678
i-87654321
i-abcd1234
```
**範例 2：此範例描述指定的 Auto Scaling 執行個體。**  

```
Get-ASAutoScalingInstance -InstanceId i-12345678
```
**輸出：**  

```
AutoScalingGroupName    : my-asg
AvailabilityZone        : us-west-2b
HealthStatus            : HEALTHY
InstanceId              : i-12345678
LaunchConfigurationName : my-lc
LifecycleState          : InService
```
**範例 3：此範例描述指定的兩個 Auto Scaling 執行個體。**  

```
Get-ASAutoScalingInstance -InstanceId @("i-12345678", "i-87654321")
```
**範例 4：此範例描述指定之 Auto Scaling 群組的 Auto Scaling 執行個體。**  

```
(Get-ASAutoScalingGroup -AutoScalingGroupName my-asg).Instances | Get-ASAutoScalingInstance
```
**範例 5：此範例描述所有 Auto Scaling 執行個體。**  

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

### `Get-ASAutoScalingNotificationType`
<a name="auto-scaling_DescribeAutoScalingNotificationTypes_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例列出 Auto Scaling 支援的通知類型。**  

```
Get-ASAutoScalingNotificationType
```
**輸出：**  

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

### `Get-ASLaunchConfiguration`
<a name="auto-scaling_DescribeLaunchConfigurations_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例列出啟動組態的名稱。**  

```
Get-ASLaunchConfiguration | format-table -property LaunchConfigurationName
```
**輸出：**  

```
LaunchConfigurationName
-----------------------
my-lc-1
my-lc-2
my-lc-3
my-lc-4
my-lc-5
```
**範例 2：此範例描述指定的啟動組態。**  

```
Get-ASLaunchConfiguration -LaunchConfigurationName my-lc-1
```
**輸出：**  

```
AssociatePublicIpAddress     : True
BlockDeviceMappings          : {/dev/xvda}
ClassicLinkVPCId             :
ClassicLinkVPCSecurityGroups : {}
CreatedTime                  : 12/12/2014 3:22:08 PM
EbsOptimized                 : False
IamInstanceProfile           :
ImageId                      : ami-043a5034
InstanceMonitoring           : Amazon.AutoScaling.Model.InstanceMonitoring
InstanceType                 : t2.micro
KernelId                     :
KeyName                      : 
LaunchConfigurationARN       : arn:aws:autoscaling:us-west-2:123456789012:launchConfiguration:7e5f31e4-693b-4604-9322-
                               e6f68d7fafad:launchConfigurationName/my-lc-1
LaunchConfigurationName      : my-lc-1
PlacementTenancy             :
RamdiskId                    :
SecurityGroups               : {sg-67ef0308}
SpotPrice                    :
UserData                     :
```
**範例 3：此範例描述指定的兩個啟動組態。**  

```
Get-ASLaunchConfiguration -LaunchConfigurationName @("my-lc-1", "my-lc-2")
```
**範例 4：此範例描述所有啟動組態。**  

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

### `Get-ASLifecycleHook`
<a name="auto-scaling_DescribeLifecycleHooks_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例描述指定的 lifecycle hook。**  

```
Get-ASLifecycleHook -AutoScalingGroupName my-asg -LifecycleHookName myLifecycleHook
```
**輸出：**  

```
AutoScalingGroupName  : my-asg
DefaultResult         : ABANDON
GlobalTimeout         : 172800
HeartbeatTimeout      : 3600
LifecycleHookName     : myLifecycleHook
LifecycleTransition   : auto-scaling:EC2_INSTANCE_LAUNCHING
NotificationMetadata  :
NotificationTargetARN : arn:aws:sns:us-west-2:123456789012:my-topic
RoleARN               : arn:aws:iam::123456789012:role/my-iam-role
```
**範例 2：此範例描述指定的 Auto Scaling 群組的 lifecycle hook。**  

```
Get-ASLifecycleHook -AutoScalingGroupName my-asg
```
**範例 3：此範例描述所有 Auto Scaling 群組的所有 lifecycle hook。**  

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

### `Get-ASLifecycleHookType`
<a name="auto-scaling_DescribeLifecycleHookTypes_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例列出 Auto Scaling 支援的 lifecycle hook 類型。**  

```
Get-ASLifecycleHookType
```
**輸出：**  

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

### `Get-ASLoadBalancer`
<a name="auto-scaling_DescribeLoadBalancers_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例描述指定的 Auto Scaling 群組的負載平衡器。**  

```
Get-ASLoadBalancer -AutoScalingGroupName my-asg
```
**輸出：**  

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

### `Get-ASMetricCollectionType`
<a name="auto-scaling_DescribeMetricCollectionTypes_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例列出 Auto Scaling 支援的指標收集類型。**  

```
(Get-ASMetricCollectionType).Metrics
```
**輸出：**  

```
Metric
------
GroupMinSize
GroupMaxSize
GroupDesiredCapacity
GroupInServiceInstances
GroupPendingInstances
GroupTerminatingInstances
GroupStandbyInstances
GroupTotalInstances
```
**範例 2：此範例列出對應的精細程度。**  

```
(Get-ASMetricCollectionType).Granularities
```
**輸出：**  

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

### `Get-ASNotificationConfiguration`
<a name="auto-scaling_DescribeNotificationConfigurations_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例描述與指定的 Auto Scaling 群組相關聯的通知動作。**  

```
Get-ASNotificationConfiguration -AutoScalingGroupName my-asg | format-list
```
**輸出：**  

```
AutoScalingGroupName : my-asg
NotificationType     : auto-scaling:EC2_INSTANCE_LAUNCH
TopicARN             : arn:aws:sns:us-west-2:123456789012:my-topic

AutoScalingGroupName : my-asg
NotificationType     : auto-scaling:EC2_INSTANCE_TERMINATE
TopicARN             : arn:aws:sns:us-west-2:123456789012:my-topic
```
**範例 2：此範例描述與所有 Auto Scaling 群組相關聯的通知動作。**  

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

### `Get-ASPolicy`
<a name="auto-scaling_DescribePolicies_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例描述指定的 Auto Scaling 群組的所有政策。**  

```
Get-ASPolicy -AutoScalingGroupName my-asg
```
**輸出：**  

```
AdjustmentType          : ChangeInCapacity
Alarms                  : {}
AutoScalingGroupName    : my-asg
Cooldown                : 0
EstimatedInstanceWarmup : 0
MetricAggregationType   :
MinAdjustmentMagnitude  : 0
MinAdjustmentStep       : 0
PolicyARN               : arn:aws:auto-scaling:us-west-2:123456789012:scalingPolicy:aa3836ab-5462-42c7-adab-e1d769fc24ef
                          :autoScalingGroupName/my-asg:policyName/myScaleInPolicy
PolicyName              : myScaleInPolicy
PolicyType              : SimpleScaling
ScalingAdjustment       : -1
StepAdjustments         : {}
```
**範例 2：此範例描述指定的 Auto Scaling 群組的指定政策。**  

```
Get-ASPolicy -AutoScalingGroupName my-asg -PolicyName @("myScaleOutPolicy", "myScaleInPolicy")
```
**範例 3：此範例描述所有 Auto Scaling 群組的所有政策。**  

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

### `Get-ASScalingActivity`
<a name="auto-scaling_DescribeScalingActivities_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例描述指定的 Auto Scaling 群組過去六週的擴展活動。**  

```
Get-ASScalingActivity -AutoScalingGroupName my-asg
```
**輸出：**  

```
ActivityId           : 063308ae-aa22-4a9b-94f4-9fae4EXAMPLE
AutoScalingGroupName : my-asg
Cause                : At 2015-11-22T15:45:16Z a user request explicitly set group desired capacity changing the desired
                       capacity from 1 to 2.  At 2015-11-22T15:45:34Z an instance was started in response to a difference
                       between desired and actual capacity, increasing the capacity from 1 to 2.
Description          : Launching a new EC2 instance: i-26e715fc
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 11/22/2015 7:46:09 AM
Progress             : 100
StartTime            : 11/22/2015 7:45:35 AM
StatusCode           : Successful
StatusMessage        :

ActivityId           : ce719997-086d-4c73-a2f1-ab703EXAMPLE
AutoScalingGroupName : my-asg
Cause                : At 2015-11-20T22:57:53Z a user request created an AutoScalingGroup changing the desired capacity
                        from 0 to 1.  At 2015-11-20T22:57:58Z an instance was started in response to a difference betwe
                       en desired and actual capacity, increasing the capacity from 0 to 1.
Description          : Launching a new EC2 instance: i-93633f9b
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 11/20/2015 2:58:32 PM
Progress             : 100
StartTime            : 11/20/2015 2:57:59 PM
StatusCode           : Successful
StatusMessage        :
```
**範例 2：此範例描述指定的擴展活動。**  

```
Get-ASScalingActivity -ActivityId "063308ae-aa22-4a9b-94f4-9fae4EXAMPLE"
```
**範例 3：此範例描述所有 Auto Scaling 群組過去六週的擴展活動。**  

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

### `Get-ASScalingProcessType`
<a name="auto-scaling_DescribeScalingProcessTypes_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例列出 Auto Scaling 支援的程序類型。**  

```
Get-ASScalingProcessType
```
**輸出：**  

```
ProcessName
-----------
AZRebalance
AddToLoadBalancer
AlarmNotification
HealthCheck
Launch
ReplaceUnhealthy
ScheduledActions
Terminate
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeScalingProcessTypes](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-ASScheduledAction`
<a name="auto-scaling_DescribeScheduledActions_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例描述指定的 Auto Scaling 群組的排程擴展動作。**  

```
Get-ASScheduledAction -AutoScalingGroupName my-asg
```
**輸出：**  

```
AutoScalingGroupName : my-asg
DesiredCapacity      : 10
EndTime              : 
MaxSize              : 
MinSize              : 
Recurrence           :
ScheduledActionARN   : arn:aws:autoscaling:us-west-2:123456789012:scheduledUpdateGroupAction:8a4c5f24-6ec6-4306-a2dd-f7
                       2c3af3a4d6:autoScalingGroupName/my-asg:scheduledActionName/myScheduledAction
ScheduledActionName  : myScheduledAction
StartTime            : 11/30/2015 8:00:00 AM
Time                 : 11/30/2015 8:00:00 AM
```
**範例 2：此範例描述指定的排程擴展動作。**  

```
Get-ASScheduledAction -ScheduledActionName @("myScheduledScaleOut", "myScheduledScaleIn")
```
**範例 3：此範例描述在指定時間開始的排程擴展動作。**  

```
Get-ASScheduledAction -StartTime "2015-12-01T08:00:00Z"
```
**範例 4：此範例描述在指定時間結束的排程擴展動作。**  

```
Get-ASScheduledAction -EndTime "2015-12-30T08:00:00Z"
```
**範例 5：此範例描述所有 Auto Scaling 群組的排程擴展動作。**  

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

### `Get-ASTag`
<a name="auto-scaling_DescribeTags_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例描述鍵值為 'myTag' 或 'myTag2' 的標籤。篩選條件名稱的可能值為 'auto-scaling-group'、'key'、'value' 和 'propagate-at-launch'。此範例使用的語法需要 PowerShell 版本 3 或更新版本。**  

```
Get-ASTag -Filter @( @{ Name="key"; Values=@("myTag", "myTag2") } )
```
**輸出：**  

```
Key               : myTag2
PropagateAtLaunch : True
ResourceId        : my-asg
ResourceType      : auto-scaling-group
Value             : myTagValue2

Key               : myTag
PropagateAtLaunch : True
ResourceId        : my-asg
ResourceType      : auto-scaling-group
Value             : myTagValue
```
**範例 2：使用 PowerShell 版本 2 時，必須使用 New-Object 來建立每個篩選條件參數的篩選條件。**  

```
$keys = New-Object string[] 2
$keys[0] = "myTag"
$keys[1] = "myTag2"
$filter = New-Object Amazon.AutoScaling.Model.Filter
$filter.Name = "key"
$filter.Values = $keys
Get-ASTag -Filter @( $filter )
```
**範例 3：此範例描述所有 Auto Scaling 群組的所有標籤。**  

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

### `Get-ASTerminationPolicyType`
<a name="auto-scaling_DescribeTerminationPolicyTypes_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例列出 Auto Scaling 支援的終止政策。**  

```
Get-ASTerminationPolicyType
```
**輸出：**  

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

### `Mount-ASInstance`
<a name="auto-scaling_AttachInstances_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的執行個體連接至指定的 Auto Scaling 群組。Auto Scaling 會自動增加 Auto Scaling 群組所需的容量。**  

```
Mount-ASInstance -InstanceId i-93633f9b -AutoScalingGroupName my-asg
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [AttachInstances](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-ASAutoScalingGroup`
<a name="auto-scaling_CreateAutoScalingGroup_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例使用指定的名稱及屬性建立 Auto Scaling 群組。預設所需容量為大小下限。因此，此 Auto Scaling 群組會啟動兩個執行個體，其中一個位於指定的兩個可用區域中。**  

```
New-ASAutoScalingGroup -AutoScalingGroupName my-asg -LaunchConfigurationName my-lc -MinSize 2 -MaxSize 6 -AvailabilityZone @("us-west-2a", "us-west-2b")
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateAutoScalingGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-ASLaunchConfiguration`
<a name="auto-scaling_CreateLaunchConfiguration_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例建立名為 'my-lc' 的啟動組態。使用此啟動組態的 Auto Scaling 群組啟動的 EC2 執行個體，會使用指定的執行個體類型、AMI、安全群組和 IAM 角色。**  

```
New-ASLaunchConfiguration -LaunchConfigurationName my-lc -InstanceType "m3.medium" -ImageId "ami-12345678" -SecurityGroup "sg-12345678" -IamInstanceProfile "myIamRole"
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateLaunchConfiguration](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-ASAutoScalingGroup`
<a name="auto-scaling_DeleteAutoScalingGroup_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：如果沒有執行中的執行個體，此範例會刪除指定的 Auto Scaling 群組。在繼續操作之前，系統會提示您確認。**  

```
Remove-ASAutoScalingGroup -AutoScalingGroupName my-asg
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-ASAutoScalingGroup (DeleteAutoScalingGroup)" on Target "my-asg".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
**範例 2：如果您指定強制參數，在繼續操作之前，系統不會提示您進行確認。**  

```
Remove-ASAutoScalingGroup -AutoScalingGroupName my-asg -Force
```
**範例 3：此範例會刪除指定的 Auto Scaling 群組，並終止其包含的任何執行中執行個體。**  

```
Remove-ASAutoScalingGroup -AutoScalingGroupName my-asg -ForceDelete $true -Force
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteAutoScalingGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-ASLaunchConfiguration`
<a name="auto-scaling_DeleteLaunchConfiguration_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：如果未連接至 Auto Scaling 群組，此範例會刪除指定的啟動組態。在繼續操作之前，系統會提示您確認。**  

```
Remove-ASLaunchConfiguration -LaunchConfigurationName my-lc
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-ASLaunchConfiguration (DeleteLaunchConfiguration)" on Target "my-lc".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
**範例 2：如果您指定強制參數，在繼續操作之前，系統不會提示您進行確認。**  

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

### `Remove-ASLifecycleHook`
<a name="auto-scaling_DeleteLifecycleHook_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例刪除指定 Auto Scaling 群組的指定 lifecycle hook。在繼續操作之前，系統會提示您確認。**  

```
Remove-ASLifecycleHook -AutoScalingGroupName my-asg -LifecycleHookName myLifecycleHook
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-ASLifecycleHook (DeleteLifecycleHook)" on Target "myLifecycleHook".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
**範例 2：如果您指定強制參數，在繼續操作之前，系統不會提示您進行確認。**  

```
Remove-ASLifecycleHook -AutoScalingGroupName my-asg -LifecycleHookName myLifecycleHook -Force
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteLifecycleHook](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-ASNotificationConfiguration`
<a name="auto-scaling_DeleteNotificationConfiguration_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會刪除指定的通知動作。在繼續操作之前，系統會提示您確認。**  

```
Remove-ASNotificationConfiguration -AutoScalingGroupName my-asg -TopicARN "arn:aws:sns:us-west-2:123456789012:my-topic"
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-ASNotificationConfiguration (DeleteNotificationConfiguration)" on Target
"arn:aws:sns:us-west-2:123456789012:my-topic".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
**範例 2：如果您指定強制參數，在繼續操作之前，系統不會提示您進行確認。**  

```
Remove-ASNotificationConfiguration -AutoScalingGroupName my-asg -TopicARN "arn:aws:sns:us-west-2:123456789012:my-topic" -Force
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteNotificationConfiguration](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-ASPolicy`
<a name="auto-scaling_DeletePolicy_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會刪除指定之 Auto Scaling 群組的指定政策。在繼續操作之前，系統會提示您確認。**  

```
Remove-ASPolicy -AutoScalingGroupName my-asg -PolicyName myScaleInPolicy
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-ASPolicy (DeletePolicy)" on Target "myScaleInPolicy".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
**範例 2：如果您指定強制參數，在繼續操作之前，系統不會提示您進行確認。**  

```
Remove-ASPolicy -AutoScalingGroupName my-asg -PolicyName myScaleInPolicy -Force
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeletePolicy](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-ASScheduledAction`
<a name="auto-scaling_DeleteScheduledAction_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會刪除指定 Auto Scaling 群組的指定排程動作。在繼續操作之前，系統會提示您確認。**  

```
Remove-ASScheduledAction -AutoScalingGroupName my-asg -ScheduledAction "myScheduledAction"
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing operation "Remove-ASScheduledAction (DeleteScheduledAction)" on Target "myScheduledAction".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
**範例 2：如果您指定強制參數，在繼續操作之前，系統不會提示您進行確認。**  

```
Remove-ASScheduledAction -AutoScalingGroupName my-asg -ScheduledAction "myScheduledAction" -Force
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteScheduledAction](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-ASTag`
<a name="auto-scaling_DeleteTags_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例從指定的 Auto Scaling 群組中移除指定的標籤。在繼續操作之前，系統會提示您確認。此範例使用的語法需要 PowerShell 版本 3 或更新版本。**  

```
Remove-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag" } )
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-ASTag (DeleteTags)" on target "Amazon.AutoScaling.Model.Tag".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
**範例 2：如果您指定強制參數，在繼續操作之前，系統不會提示您進行確認。**  

```
Remove-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag" } ) -Force
```
**範例 3：使用 Powershell 版本 2 時，必須使用 New-Object 來建立 Tag 參數的標籤。**  

```
$tag = New-Object Amazon.AutoScaling.Model.Tag
$tag.ResourceType = "auto-scaling-group"
$tag.ResourceId = "my-asg"
$tag.Key = "myTag"
Remove-ASTag -Tag $tag -Force
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteTags](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Resume-ASProcess`
<a name="auto-scaling_ResumeProcesses_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例恢復指定的 Auto Scaling 群組的指定 Auto Scaling 程序。**  

```
Resume-ASProcess -AutoScalingGroupName my-asg -ScalingProcess "AlarmNotification"
```
**範例 2：此範例恢復指定的 Auto Scaling 群組的所有暫停 Auto Scaling 處理程序。**  

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

### `Set-ASDesiredCapacity`
<a name="auto-scaling_SetDesiredCapacity_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例設定指定的 Auto Scaling 群組的大小。**  

```
Set-ASDesiredCapacity -AutoScalingGroupName my-asg -DesiredCapacity 2
```
**範例 2：此範例設定指定 Auto Scaling 群組的大小，並等待冷卻時間告一段落，然後再擴展到新的大小。**  

```
Set-ASDesiredCapacity -AutoScalingGroupName my-asg -DesiredCapacity 2 -HonorCooldown $true
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [SetDesiredCapacity](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-ASInstanceHealth`
<a name="auto-scaling_SetInstanceHealth_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定之執行個體的狀態設定為「運作狀態不良」，使其停止服務。Auto Scaling 會終止並取代執行個體。**  

```
Set-ASInstanceHealth -HealthStatus Unhealthy -InstanceId i-93633f9b
```
**範例 2：此範例將指定之執行個體的狀態設定為「運作狀態良好」，使其保持服務中狀態。Auto Scaling 群組的運作狀態檢查寬限期未遵循。**  

```
Set-ASInstanceHealth -HealthStatus Healthy -InstanceId i-93633f9b -ShouldRespectGracePeriod $false
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [SetInstanceHealth](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-ASInstanceProtection`
<a name="auto-scaling_SetInstanceProtection_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例啟用指定之執行個體的執行個體保護功能。**  

```
Set-ASInstanceProtection -AutoScalingGroupName my-asg -InstanceId i-12345678 -ProtectedFromScaleIn $true
```
**範例 2：此範例停用指定之執行個體的執行個體保護功能。**  

```
Set-ASInstanceProtection -AutoScalingGroupName my-asg -InstanceId i-12345678 -ProtectedFromScaleIn $false
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [SetInstanceProtection](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-ASTag`
<a name="auto-scaling_CreateOrUpdateTags_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將單一標籤新增至指定的 Auto Scaling 群組。標籤索引鍵為 'myTag'，標籤值為 'myTagValue'。Auto Scaling 會將此標籤傳播到 Auto Scaling 群組啟動的後續 EC2 執行個體。此範例使用的語法需要 PowerShell 版本 3 或更新版本。**  

```
Set-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag"; Value="myTagValue"; PropagateAtLaunch=$true} )
```
**範例 2：使用 PowerShell 版本 2 時，必須使用 New-Object 來建立 Tag 參數的標籤。**  

```
$tag = New-Object Amazon.AutoScaling.Model.Tag
$tag.ResourceType = "auto-scaling-group"
$tag.ResourceId = "my-asg" 
$tag.Key = "myTag" 
$tag.Value = "myTagValue"
$tag.PropagateAtLaunch = $true
Set-ASTag -Tag $tag
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateOrUpdateTags](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Start-ASPolicy`
<a name="auto-scaling_ExecutePolicy_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例為指定的 Auto Scaling 群組執行指定的政策。**  

```
Start-ASPolicy -AutoScalingGroupName my-asg -PolicyName "myScaleInPolicy"
```
**範例 2：此範例在等待冷卻時間告一段落之後，為指定的 Auto Scaling 群組執行指定的政策。**  

```
Start-ASPolicy -AutoScalingGroupName my-asg -PolicyName "myScaleInPolicy" -HonorCooldown $true
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [ExecutePolicy](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Stop-ASInstanceInAutoScalingGroup`
<a name="auto-scaling_TerminateInstanceInAutoScalingGroup_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例終止了指定的執行個體，並減少其 Auto Scaling 群組所需的容量，如此 Auto Scaling 就不會啟動替代執行個體。**  

```
Stop-ASInstanceInAutoScalingGroup -InstanceId i-93633f9b -ShouldDecrementDesiredCapacity $true
```
**輸出：**  

```
ActivityId           : 2e40d9bd-1902-444c-abf3-6ea0002efdc5
AutoScalingGroupName :
Cause                : At 2015-11-22T16:09:03Z instance i-93633f9b was taken out of service in response to a user 
                       request, shrinking the capacity from 2 to 1.
Description          : Terminating EC2 instance: i-93633f9b
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 
Progress             : 0
StartTime            : 11/22/2015 8:09:03 AM
StatusCode           : InProgress
StatusMessage        :
```
**範例 2：此範例終止了指定的執行個體，但未減少其 Auto Scaling 群組所需的容量。Auto Scaling 會啟動替代執行個體。**  

```
Stop-ASInstanceInAutoScalingGroup -InstanceId i-93633f9b -ShouldDecrementDesiredCapacity $false
```
**輸出：**  

```
ActivityId           : 2e40d9bd-1902-444c-abf3-6ea0002efdc5
AutoScalingGroupName :
Cause                : At 2015-11-22T16:09:03Z instance i-93633f9b was taken out of service in response to a user 
                       request.
Description          : Terminating EC2 instance: i-93633f9b
Details              : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"}
EndTime              : 
Progress             : 0
StartTime            : 11/22/2015 8:09:03 AM
StatusCode           : InProgress
StatusMessage        :
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [TerminateInstanceInAutoScalingGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Suspend-ASProcess`
<a name="auto-scaling_SuspendProcesses_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例暫停指定的 Auto Scaling 群組的指定 Auto Scaling 處理程序。**  

```
Suspend-ASProcess -AutoScalingGroupName my-asg -ScalingProcess "AlarmNotification"
```
**範例 2：此範例暫停指定的 Auto Scaling 群組的所有 Auto Scaling 處理程序。**  

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

### `Update-ASAutoScalingGroup`
<a name="auto-scaling_UpdateAutoScalingGroup_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例更新指定的 Auto Scaling 群組的大小下限和上限。**  

```
Update-ASAutoScalingGroup -AutoScalingGroupName my-asg -MaxSize 5 -MinSize 1
```
**範例 2：此範例更新指定的 Auto Scaling 群組的預設冷卻時間。**  

```
Update-ASAutoScalingGroup -AutoScalingGroupName my-asg -DefaultCooldown 10
```
**範例 3：此範例更新指定的 Auto Scaling 群組的可用區域。**  

```
Update-ASAutoScalingGroup -AutoScalingGroupName my-asg -AvailabilityZone @("us-west-2a", "us-west-2b")
```
**範例 4：此範例更新指定的 Auto Scaling 群組，使用 Elastic Load Balancing 運作狀態檢查。**  

```
Update-ASAutoScalingGroup -AutoScalingGroupName my-asg -HealthCheckType ELB -HealthCheckGracePeriod 60
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateAutoScalingGroup](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Write-ASLifecycleActionHeartbeat`
<a name="auto-scaling_RecordLifecycleActionHeartbeat_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例記錄指定的生命週期動作的活動訊號。這會使執行個體保持待定狀態，直到您完成自訂動作為止。**  

```
Write-ASLifecycleActionHeartbeat -AutoScalingGroupName my-asg -LifecycleHookName myLifecycleHook -LifecycleActionToken bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RecordLifecycleActionHeartbeat](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Write-ASLifecycleHook`
<a name="auto-scaling_PutLifecycleHook_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的 lifecycle hook 新增至指定的 Auto Scaling 群組。**  

```
Write-ASLifecycleHook -AutoScalingGroupName my-asg -LifecycleHookName "myLifecycleHook" -LifecycleTransition "autoscaling:EC2_INSTANCE_LAUNCHING" -NotificationTargetARN "arn:aws:sns:us-west-2:123456789012:my-sns-topic" -RoleARN "arn:aws:iam::123456789012:role/my-iam-role"
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [PutLifecycleHook](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Write-ASNotificationConfiguration`
<a name="auto-scaling_PutNotificationConfiguration_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的 Auto Scaling 群組設定為在啟動 EC2 執行個體時，傳送通知至指定的 SNS 主題。**  

```
Write-ASNotificationConfiguration -AutoScalingGroupName my-asg -NotificationType "autoscaling:EC2_INSTANCE_LAUNCH" -TopicARN "arn:aws:sns:us-west-2:123456789012:my-topic"
```
**範例 2：此範例將指定的 Auto Scaling 群組設定為在啟動或終止 EC2 執行個體時，傳送通知至指定的 SNS 主題。**  

```
Write-ASNotificationConfiguration -AutoScalingGroupName my-asg -NotificationType @("autoscaling:EC2_INSTANCE_LAUNCH", "autoscaling:EC2_INSTANCE_TERMINATE") -TopicARN "arn:aws:sns:us-west-2:123456789012:my-topic"
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [PutNotificationConfiguration](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Write-ASScalingPolicy`
<a name="auto-scaling_PutScalingPolicy_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例將指定的政策新增至指定的 Auto Scaling 群組。指定的調整類 型決定如何解譯 ScalingAdjustment 參數。使用 'ChangeInCapacity' 時，正值會增加指定的執行個體數量的容量，負值則會減少指定的執行個體數量的容量。**  

```
Write-ASScalingPolicy -AutoScalingGroupName my-asg -AdjustmentType "ChangeInCapacity" -PolicyName "myScaleInPolicy" -ScalingAdjustment -1
```
**輸出：**  

```
arn:aws:autoscaling:us-west-2:123456789012:scalingPolicy:aa3836ab-5462-42c7-adab-e1d769fc24ef:autoScalingGroupName/my-asg
:policyName/myScaleInPolicy
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [PutScalingPolicy](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Write-ASScheduledUpdateGroupAction`
<a name="auto-scaling_PutScheduledUpdateGroupAction_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會建立或更新一次性排程動作，以在指定的開始時間變更所需的容量。**  

```
Write-ASScheduledUpdateGroupAction -AutoScalingGroupName my-asg -ScheduledActionName "myScheduledAction" -StartTime "2015-12-01T00:00:00Z" -DesiredCapacity 10
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [PutScheduledUpdateGroupAction](https://docs.aws.amazon.com/powershell/v5/reference)。