

的版本 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)

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

# 使用适用于 PowerShell V5 的工具的 Auto Scaling 示例
<a name="powershell_auto-scaling_code_examples"></a>

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

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

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

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

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

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的负载均衡器附加到指定的自动扩缩组。**  

```
Add-ASLoadBalancer -LoadBalancerName my-lb -AutoScalingGroupName my-asg
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AttachLoadBalancers](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Complete-ASLifecycleAction`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例完成了指定的生命周期操作。**  

```
Complete-ASLifecycleAction -LifecycleHookName myLifecycleHook -AutoScalingGroupName my-asg -LifecycleActionResult CONTINUE -LifecycleActionToken bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CompleteLifecycleAction](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Disable-ASMetricsCollection`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例禁用对指定自动扩缩组指定指标的监控。**  

```
Disable-ASMetricsCollection -AutoScalingGroupName my-asg -Metric @("GroupMinSize", "GroupMaxSize")
```
**示例 2：此示例禁用对指定自动扩缩组所有指标的监控。**  

```
Disable-ASMetricsCollection -AutoScalingGroupName my-asg
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DisableMetricsCollection](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Dismount-ASInstance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的实例与指定的自动扩缩组分离，并减少所需容量以使 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 会启动一个替换实例。**  

```
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 参考 (V* 5) [DetachInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Dismount-ASLoadBalancer`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的负载均衡器与指定的自动扩缩组分离。**  

```
Dismount-ASLoadBalancer -LoadBalancerName my-lb -AutoScalingGroupName my-asg
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DetachLoadBalancers](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Enable-ASMetricsCollection`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例启用对指定自动扩缩组指定指标的监控。**  

```
Enable-ASMetricsCollection  -Metric @("GroupMinSize", "GroupMaxSize") -AutoScalingGroupName my-asg -Granularity 1Minute
```
**示例 2：此示例启用对指定自动扩缩组所有指标的监控。**  

```
Enable-ASMetricsCollection -AutoScalingGroupName my-asg -Granularity 1Minute
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [EnableMetricsCollection](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Enter-ASStandby`。

**适用于 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 参考 (V* 5) [EnterStandby](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Exit-ASStandby`。

**适用于 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 参考 (V* 5) [ExitStandby](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述了您的 AWS 账户的 Auto Scaling 资源限制。**  

```
Get-ASAccountLimit
```
**输出**：  

```
MaxNumberOfAutoScalingGroups    : 20
MaxNumberOfLaunchConfigurations : 100
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeAccountLimits](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述 Auto Scaling 所支持的调整类型。**  

```
Get-ASAdjustmentType
```
**输出**：  

```
Type
----
ChangeInCapacity
ExactCapacity
PercentChangeInCapacity
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeAdjustmentTypes](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例列出自动扩缩组的名称。**  

```
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：此示例描述指定的自动扩缩组。**  

```
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：此示例描述指定的两个自动扩缩组。**  

```
Get-ASAutoScalingGroup -AutoScalingGroupName @("my-asg-1", "my-asg-2")
```
**示例 4：此示例描述指定自动扩缩组的 Auto Scaling 实例。**  

```
(Get-ASAutoScalingGroup -AutoScalingGroupName my-asg-1).Instances
```
**示例 5：此示例描述所有自动扩缩组。**  

```
Get-ASAutoScalingGroup
```
**示例 6：此示例描述了指定 LaunchTemplate 的 Auto Scaling 组。此示例假设“实例购买选项”设置为“遵照启动模板”。如果此选项设置为 “合并购买选项和实例类型”，则 LaunchTemplate 可以使用 “进行访问MixedInstancesPolicy。 LaunchTemplate“财产。**  

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

```
LaunchTemplateId     LaunchTemplateName   Version
----------------     ------------------   -------
lt-06095fd619cb40371 test-launch-template $Default
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeAutoScalingGroups](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例列出了您的 IDs Auto Scaling 实例。**  

```
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 实例。**  

```
(Get-ASAutoScalingGroup -AutoScalingGroupName my-asg).Instances | Get-ASAutoScalingInstance
```
**示例 5：此示例描述所有 Auto Scaling 实例。**  

```
Get-ASAutoScalingInstance
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeAutoScalingInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 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 参考 (V* 5) [DescribeAutoScalingNotificationTypes](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 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 参考 (V* 5) [DescribeLaunchConfigurations](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定的生命周期挂钩。**  

```
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：此示例描述指定自动扩缩组的所有生命周期挂钩。**  

```
Get-ASLifecycleHook -AutoScalingGroupName my-asg
```
**示例 3：此示例描述所有自动扩缩组的所有生命周期挂钩。**  

```
Get-ASLifecycleHook
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeLifecycleHooks](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例列出 Auto Scaling 支持的生命周期挂钩类型。**  

```
Get-ASLifecycleHookType
```
**输出**：  

```
autoscaling:EC2_INSTANCE_LAUNCHING
auto-scaling:EC2_INSTANCE_TERMINATING
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeLifecycleHookTypes](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定自动扩缩组的负载均衡器。**  

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

```
LoadBalancerName    State
----------------    -----
my-lb               Added
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeLoadBalancers](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 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 参考 (V* 5) [DescribeMetricCollectionTypes](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述与指定自动扩缩组关联的通知操作。**  

```
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：此示例描述与所有自动扩缩组关联的通知操作。**  

```
Get-ASNotificationConfiguration
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeNotificationConfigurations](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定自动扩缩组的所有策略。**  

```
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：此示例描述指定自动扩缩组的指定策略。**  

```
Get-ASPolicy -AutoScalingGroupName my-asg -PolicyName @("myScaleOutPolicy", "myScaleInPolicy")
```
**示例 3：此示例描述所有自动扩缩组的所有策略。**  

```
Get-ASPolicy
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribePolicies](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定自动扩缩组过去六周的扩缩活动。**  

```
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：此示例描述所有自动扩缩组过去六周的扩缩活动。**  

```
Get-ASScalingActivity
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeScalingActivities](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例列出 Auto Scaling 支持的进程类型。**  

```
Get-ASScalingProcessType
```
**输出**：  

```
ProcessName
-----------
AZRebalance
AddToLoadBalancer
AlarmNotification
HealthCheck
Launch
ReplaceUnhealthy
ScheduledActions
Terminate
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeScalingProcessTypes](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例描述指定自动扩缩组的计划扩缩操作。**  

```
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：此示例描述所有自动扩缩组的计划扩缩操作。**  

```
Get-ASScheduledAction
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeScheduledActions](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 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：此示例描述所有自动扩缩组的所有标签。**  

```
Get-ASTag
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeTags](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例列出 Auto Scaling 支持的终止策略。**  

```
Get-ASTerminationPolicyType
```
**输出**：  

```
ClosestToNextInstanceHour
Default
NewestInstance
OldestInstance
OldestLaunchConfiguration
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeTerminationPolicyTypes](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Mount-ASInstance`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的实例附加到指定的自动扩缩组。Auto Scaling 会自动增加自动扩缩组的所需容量。**  

```
Mount-ASInstance -InstanceId i-93633f9b -AutoScalingGroupName my-asg
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [AttachInstances](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例使用指定的名称和属性创建自动扩缩组。默认所需容量为最小大小。因此，此自动扩缩组启动两个实例，指定的两个可用区中各一个。**  

```
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 参考 (V* 5) [CreateAutoScalingGroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 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 参考 (V* 5) [CreateLaunchConfiguration](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：如果指定的自动扩缩组没有正在运行的实例，则此示例将删除该组。在操作继续之前，系统会提示您进行确认。**  

```
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：如果您指定 Force 参数，则在操作继续之前，系统不会提示您进行确认。**  

```
Remove-ASAutoScalingGroup -AutoScalingGroupName my-asg -Force
```
**示例 3：此示例删除指定的自动扩缩组并终止该组包含的所有正在运行的实例。**  

```
Remove-ASAutoScalingGroup -AutoScalingGroupName my-asg -ForceDelete $true -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteAutoScalingGroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：如果指定的启动配置未附加到自动扩缩组，则此示例将删除该配置。在操作继续之前，系统会提示您进行确认。**  

```
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：如果您指定 Force 参数，则在操作继续之前，系统不会提示您进行确认。**  

```
Remove-ASLaunchConfiguration -LaunchConfigurationName my-lc -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteLaunchConfiguration](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定自动扩缩组的指定生命周期挂钩。在操作继续之前，系统会提示您进行确认。**  

```
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：如果您指定 Force 参数，则在操作继续之前，系统不会提示您进行确认。**  

```
Remove-ASLifecycleHook -AutoScalingGroupName my-asg -LifecycleHookName myLifecycleHook -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteLifecycleHook](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 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：如果您指定 Force 参数，则在操作继续之前，系统不会提示您进行确认。**  

```
Remove-ASNotificationConfiguration -AutoScalingGroupName my-asg -TopicARN "arn:aws:sns:us-west-2:123456789012:my-topic" -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteNotificationConfiguration](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定自动扩缩组的指定策略。在操作继续之前，系统会提示您进行确认。**  

```
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：如果您指定 Force 参数，则在操作继续之前，系统不会提示您进行确认。**  

```
Remove-ASPolicy -AutoScalingGroupName my-asg -PolicyName myScaleInPolicy -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeletePolicy](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例删除指定自动扩缩组的指定计划操作。在操作继续之前，系统会提示您进行确认。**  

```
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：如果您指定 Force 参数，则在操作继续之前，系统不会提示您进行确认。**  

```
Remove-ASScheduledAction -AutoScalingGroupName my-asg -ScheduledAction "myScheduledAction" -Force
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteScheduledAction](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例从指定的自动扩缩组删除指定的标签。在操作继续之前，系统会提示您进行确认。此示例使用的语法需要 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：如果您指定 Force 参数，则在操作继续之前，系统不会提示您进行确认。**  

```
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 参考 (V* 5) [DeleteTags](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Resume-ASProcess`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例恢复指定自动扩缩组的指定 Auto Scaling 进程。**  

```
Resume-ASProcess -AutoScalingGroupName my-asg -ScalingProcess "AlarmNotification"
```
**示例 2：此示例恢复指定自动扩缩组的所有暂停 Auto Scaling 进程。**  

```
Resume-ASProcess -AutoScalingGroupName my-asg
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ResumeProcesses](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Set-ASDesiredCapacity`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例设置指定自动扩缩组的大小。**  

```
Set-ASDesiredCapacity -AutoScalingGroupName my-asg -DesiredCapacity 2
```
**示例 2：此示例设置指定自动扩缩组的大小，并等待冷却时间结束后再扩缩到新大小。**  

```
Set-ASDesiredCapacity -AutoScalingGroupName my-asg -DesiredCapacity 2 -HonorCooldown $true
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [SetDesiredCapacity](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Set-ASInstanceHealth`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定实例的状态设置为“运行状况不佳”，使其停止服务。Auto Scaling 会终止并替换该实例。**  

```
Set-ASInstanceHealth -HealthStatus Unhealthy -InstanceId i-93633f9b
```
**示例 2：此示例将指定实例的状态设置为“运行状况正常”，使其保持服务状态。未遵守自动扩缩组的任何运行状况检查宽限期。**  

```
Set-ASInstanceHealth -HealthStatus Healthy -InstanceId i-93633f9b -ShouldRespectGracePeriod $false
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [SetInstanceHealth](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Set-ASInstanceProtection`。

**适用于 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 参考 (V* 5) [SetInstanceProtection](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Set-ASTag`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例向指定的自动扩缩组添加单个标签。标签键为 “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 = 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 参考 (V* 5) [CreateOrUpdateTags](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Start-ASPolicy`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例对指定的自动扩缩组执行指定的策略。**  

```
Start-ASPolicy -AutoScalingGroupName my-asg -PolicyName "myScaleInPolicy"
```
**示例 2：此示例在等待冷却时间结束后，对指定的自动扩缩组执行指定的策略。**  

```
Start-ASPolicy -AutoScalingGroupName my-asg -PolicyName "myScaleInPolicy" -HonorCooldown $true
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ExecutePolicy](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例终止了指定的实例，并减少其自动扩缩组的所需容量，以使 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 会启动一个替换实例。**  

```
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 参考 (V* 5) [TerminateInstanceInAutoScalingGroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Suspend-ASProcess`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例暂停了指定自动扩缩组的指定 Auto Scaling 进程。**  

```
Suspend-ASProcess -AutoScalingGroupName my-asg -ScalingProcess "AlarmNotification"
```
**示例 2：此示例暂停了指定自动扩缩组的所有 Auto Scaling 进程。**  

```
Suspend-ASProcess -AutoScalingGroupName my-asg
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [SuspendProcesses](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例更新指定自动扩缩组的最小和最大大小。**  

```
Update-ASAutoScalingGroup -AutoScalingGroupName my-asg -MaxSize 5 -MinSize 1
```
**示例 2：此示例更新指定自动扩缩组的默认冷却时间。**  

```
Update-ASAutoScalingGroup -AutoScalingGroupName my-asg -DefaultCooldown 10
```
**示例 3：此示例更新指定自动扩缩组的可用区。**  

```
Update-ASAutoScalingGroup -AutoScalingGroupName my-asg -AvailabilityZone @("us-west-2a", "us-west-2b")
```
**示例 4：此示例更新指定的自动扩缩组以使用 Elastic Load Balancing 运行状况检查。**  

```
Update-ASAutoScalingGroup -AutoScalingGroupName my-asg -HealthCheckType ELB -HealthCheckGracePeriod 60
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UpdateAutoScalingGroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Write-ASLifecycleActionHeartbeat`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例记录指定生命周期操作的心跳。这会使实例保持待处理状态，直到您完成自定义操作。**  

```
Write-ASLifecycleActionHeartbeat -AutoScalingGroupName my-asg -LifecycleHookName myLifecycleHook -LifecycleActionToken bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RecordLifecycleActionHeartbeat](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Write-ASLifecycleHook`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的生命周期挂钩添加到指定的自动扩缩组。**  

```
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 参考 (V* 5) [PutLifecycleHook](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Write-ASNotificationConfiguration`。

**适用于 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 参考 (V* 5) [PutNotificationConfiguration](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Write-ASScalingPolicy`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的策略添加到指定的自动扩缩组。指定的调整类型决定了如何解释 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 参考 (V* 5) [PutScalingPolicy](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

以下代码示例演示了如何使用 `Write-ASScheduledUpdateGroupAction`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建或更新一次性计划操作，以在指定的开始时间更改所需容量。**  

```
Write-ASScheduledUpdateGroupAction -AutoScalingGroupName my-asg -ScheduledActionName "myScheduledAction" -StartTime "2015-12-01T00:00:00Z" -DesiredCapacity 10
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [PutScheduledUpdateGroupAction](https://docs.aws.amazon.com/powershell/v5/reference)中的。