

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

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

# 使用 PowerShell V4 版工具的 Systems Manager 示例
<a name="powershell_4_ssm_code_examples"></a>

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

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

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

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

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

### `Add-SSMResourceTag`
<a name="ssm_AddTagsToResource_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用新标签更新维护时段。如果此命令成功，则无任何输出。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$option1 = @{Key="Stack";Value=@("Production")}
Add-SSMResourceTag -ResourceId "mw-03eb9db42890fb82d" -ResourceType "MaintenanceWindow" -Tag $option1
```
**示例 2：在 PowerShell 版本 2 中，必须使用 New-Object 来创建每个标签。如果此命令成功，则无任何输出。**  

```
$tag1 = New-Object Amazon.SimpleSystemsManagement.Model.Tag
$tag1.Key = "Stack"
$tag1.Value = "Production"
		
Add-SSMResourceTag -ResourceId "mw-03eb9db42890fb82d" -ResourceType "MaintenanceWindow" -Tag $tag1
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [AddTagsToResource](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Edit-SSMDocumentPermission`
<a name="ssm_ModifyDocumentPermission_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Edit-SSMDocumentPermission`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例为文档的所有账户添加“共享”权限。如果此命令成功，则无任何输出。**  

```
Edit-SSMDocumentPermission -Name "RunShellScript" -PermissionType "Share" -AccountIdsToAdd all
```
**示例 2：此示例为文档的特定账户添加“共享”权限。如果此命令成功，则无任何输出。**  

```
Edit-SSMDocumentPermission -Name "RunShellScriptNew" -PermissionType "Share" -AccountIdsToAdd "123456789012"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ModifyDocumentPermission](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMActivation`
<a name="ssm_DescribeActivations_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例提供有关您账户激活的详细信息。**  

```
Get-SSMActivation
```
**输出**：  

```
ActivationId        : 08e51e79-1e36-446c-8e63-9458569c1363
CreatedDate         : 3/1/2017 12:01:51 AM
DefaultInstanceName : MyWebServers
Description         :
ExpirationDate      : 3/2/2017 12:01:51 AM
Expired             : False
IamRole             : AutomationRole
RegistrationLimit   : 10
RegistrationsCount  : 0
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeActivations](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAssociation`
<a name="ssm_DescribeAssociation_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例描述实例和文档之间的关联。**  

```
Get-SSMAssociation -InstanceId "i-0000293ffd8c57862" -Name "AWS-UpdateSSMAgent"
```
**输出**：  

```
Name                  : AWS-UpdateSSMAgent
InstanceId            : i-0000293ffd8c57862
Date                  : 2/23/2017 6:55:22 PM
Status.Name           : Pending
Status.Date           : 2/20/2015 8:31:11 AM
Status.Message        : temp_status_change
Status.AdditionalInfo : Additional-Config-Needed
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeAssociation](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAssociationExecution`
<a name="ssm_DescribeAssociationExecutions_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例返回所提供关联 ID 的执行**  

```
Get-SSMAssociationExecution -AssociationId 123a45a0-c678-9012-3456-78901234db5e
```
**输出**：  

```
AssociationId         : 123a45a0-c678-9012-3456-78901234db5e
AssociationVersion    : 2
CreatedTime           : 3/2/2019 8:53:29 AM
DetailedStatus        :
ExecutionId           : 123a45a0-c678-9012-3456-78901234db5e
LastExecutionDate     : 1/1/0001 12:00:00 AM
ResourceCountByStatus : {Success=4}
Status                : Success
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeAssociationExecutions](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAssociationExecutionTarget`
<a name="ssm_DescribeAssociationExecutionTargets_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示作为关联执行目标组成部分的资源 ID 及其执行状态**  

```
Get-SSMAssociationExecutionTarget -AssociationId 123a45a0-c678-9012-3456-78901234db5e -ExecutionId 123a45a0-c678-9012-3456-78901234db5e | Select-Object ResourceId, Status
```
**输出**：  

```
ResourceId           Status
----------           ------
i-0b1b2a3456f7a890b  Success
i-01c12a45d6fc7a89f  Success
i-0a1caf234f56d7dc8  Success
i-012a3fd45af6dbcfe  Failed
i-0ddc1df23c4a5fb67  Success
```
**示例 2：此命令检查自昨天以来与命令文档关联的特定自动化的特定执行。它会进一步检查关联执行是否失败；如果失败，它将显示执行的命令调用详细信息以及实例 ID**  

```
$AssociationExecution= Get-SSMAssociationExecutionTarget -AssociationId 1c234567-890f-1aca-a234-5a678d901cb0 -ExecutionId 12345ca12-3456-2345-2b45-23456789012 | 
    Where-Object {$_.LastExecutionDate -gt (Get-Date -Hour 00 -Minute 00).AddDays(-1)} 

foreach ($execution in $AssociationExecution) {
    if($execution.Status -ne 'Success'){
        Write-Output "There was an issue executing the association $($execution.AssociationId) on $($execution.ResourceId)"
        Get-SSMCommandInvocation -CommandId $execution.OutputSource.OutputSourceId -Detail:$true | Select-Object -ExpandProperty CommandPlugins
    }
}
```
**输出**：  

```
There was an issue executing the association 1c234567-890f-1aca-a234-5a678d901cb0 on i-0a1caf234f56d7dc8


Name                   : aws:runPowerShellScript
Output                 : 
                         ----------ERROR-------
                         failed to run commands: exit status 1
OutputS3BucketName     : 
OutputS3KeyPrefix      : 
OutputS3Region         : eu-west-1
ResponseCode           : 1
ResponseFinishDateTime : 5/29/2019 11:04:49 AM
ResponseStartDateTime  : 5/29/2019 11:04:49 AM
StandardErrorUrl       : 
StandardOutputUrl      : 
Status                 : Failed
StatusDetails          : Failed
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeAssociationExecutionTargets](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAssociationList`
<a name="ssm_ListAssociations_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出实例的所有关联。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$filter1 = @{Key="InstanceId";Value=@("i-0000293ffd8c57862")}
Get-SSMAssociationList -AssociationFilterList $filter1
```
**输出**：  

```
AssociationId      : d8617c07-2079-4c18-9847-1655fc2698b0
DocumentVersion    :
InstanceId         : i-0000293ffd8c57862
LastExecutionDate  : 2/20/2015 8:31:11 AM
Name               : AWS-UpdateSSMAgent
Overview           : Amazon.SimpleSystemsManagement.Model.AssociationOverview
ScheduleExpression :
Targets            : {InstanceIds}
```
**示例 2：此示例列出配置文档的所有关联。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$filter2 = @{Key="Name";Value=@("AWS-UpdateSSMAgent")}
Get-SSMAssociationList -AssociationFilterList $filter2
```
**输出**：  

```
AssociationId      : d8617c07-2079-4c18-9847-1655fc2698b0
DocumentVersion    :
InstanceId         : i-0000293ffd8c57862
LastExecutionDate  : 2/20/2015 8:31:11 AM
Name               : AWS-UpdateSSMAgent
Overview           : Amazon.SimpleSystemsManagement.Model.AssociationOverview
ScheduleExpression :
Targets            : {InstanceIds}
```
**示例 3：在 PowerShell 版本 2 中，必须使用 New-Object 来创建每个滤镜。**  

```
$filter1 = New-Object Amazon.SimpleSystemsManagement.Model.AssociationFilter
$filter1.Key = "InstanceId"
$filter1.Value = "i-0000293ffd8c57862"

Get-SSMAssociationList -AssociationFilterList $filter1
```
**输出**：  

```
AssociationId      : d8617c07-2079-4c18-9847-1655fc2698b0
DocumentVersion    :
InstanceId         : i-0000293ffd8c57862
LastExecutionDate  : 2/20/2015 8:31:11 AM
Name               : AWS-UpdateSSMAgent
Overview           : Amazon.SimpleSystemsManagement.Model.AssociationOverview
ScheduleExpression :
Targets            : {InstanceIds}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListAssociations](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAssociationVersionList`
<a name="ssm_ListAssociationVersions_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例检索所提供关联的所有版本。**  

```
Get-SSMAssociationVersionList -AssociationId 123a45a0-c678-9012-3456-78901234db5e
```
**输出**：  

```
AssociationId      : 123a45a0-c678-9012-3456-78901234db5e
AssociationName    :
AssociationVersion : 2
ComplianceSeverity :
CreatedDate        : 3/12/2019 9:21:01 AM
DocumentVersion    :
MaxConcurrency     :
MaxErrors          :
Name               : AWS-GatherSoftwareInventory
OutputLocation     :
Parameters         : {}
ScheduleExpression :
Targets            : {InstanceIds}

AssociationId      : 123a45a0-c678-9012-3456-78901234db5e
AssociationName    : test-case-1234567890
AssociationVersion : 1
ComplianceSeverity :
CreatedDate        : 3/2/2019 8:53:29 AM
DocumentVersion    :
MaxConcurrency     :
MaxErrors          :
Name               : AWS-GatherSoftwareInventory
OutputLocation     :
Parameters         : {}
ScheduleExpression : rate(30minutes)
Targets            : {InstanceIds}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListAssociationVersions](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAutomationExecution`
<a name="ssm_GetAutomationExecution_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示自动化执行的详细信息。**  

```
Get-SSMAutomationExecution -AutomationExecutionId "4105a4fc-f944-11e6-9d32-8fb2db27a909"
```
**输出**：  

```
AutomationExecutionId     : 4105a4fc-f944-11e6-9d32-8fb2db27a909
AutomationExecutionStatus : Failed
DocumentName              : AWS-UpdateLinuxAmi
DocumentVersion           : 1
ExecutionEndTime          : 2/22/2017 9:17:08 PM
ExecutionStartTime        : 2/22/2017 9:17:02 PM
FailureMessage            : Step launchInstance failed maximum allowed times. You are not authorized to perform this operation. Encoded
                            authorization failure message: B_V2QyyN7NhSZQYpmVzpEc4oSnj2GLTNYnXUHsTbqJkNMoDgubmbtthLmZyaiUYekORIrA42-fv1x-04q5Fjff6glh
                            Yb6TI5b0GQeeNrpwNvpDzmO-PSR1swlAbg9fdM9BcNjyrznspUkWpuKu9EC1Ou6v3OXU1KC9nZ7mPlWMFZNkSioQqpwWEvMw-GZktsQzm67qOhUhBNOLWYhbS
                            pkfiqzY-5nw3S0obx30fhd3EJa5O_-GjV_a0nFXQJa70ik40bFOrEh3MtCSbrQT6--DvFy_FQ8TKvkIXadyVskeJI84XOF5WmA60f1pi5GI08i-nRfZS6oDeU
                            gELBjjoFKD8s3L2aI0B6umWVxnQOjqhQRxwJ53b54sZJ2PW3v_mtg9-q0CK0ezS3xfh_y0ilaUGOAZG-xjQFuvU_JZedWpla3xi-MZsmblAifBI
                            (Service: AmazonEC2; Status Code: 403; Error Code: UnauthorizedOperation; Request ID:
                            6a002f94-ba37-43fd-99e6-39517715fce5)
Outputs                   : {[createImage.ImageId, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]}
Parameters                : {[AutomationAssumeRole, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]], [InstanceIamRole,
                            Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]], [SourceAmiId,
                            Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]}
StepExecutions            : {launchInstance, updateOSSoftware, stopInstance, createImage...}
```
**示例 2：此示例列出给定自动化执行 ID 的步骤详细信息**  

```
Get-SSMAutomationExecution -AutomationExecutionId e1d2bad3-4567-8901-ae23-456c7c8901be | Select-Object -ExpandProperty StepExecutions | Select-Object StepName, Action, StepStatus, ValidNextSteps
```
**输出**：  

```
StepName                  Action                  StepStatus ValidNextSteps
--------                  ------                  ---------- --------------
LaunchInstance            aws:runInstances        Success    {OSCompatibilityCheck}
OSCompatibilityCheck      aws:runCommand          Success    {RunPreUpdateScript}
RunPreUpdateScript        aws:runCommand          Success    {UpdateEC2Config}
UpdateEC2Config           aws:runCommand          Cancelled  {}
UpdateSSMAgent            aws:runCommand          Pending    {}
UpdateAWSPVDriver         aws:runCommand          Pending    {}
UpdateAWSEnaNetworkDriver aws:runCommand          Pending    {}
UpdateAWSNVMe             aws:runCommand          Pending    {}
InstallWindowsUpdates     aws:runCommand          Pending    {}
RunPostUpdateScript       aws:runCommand          Pending    {}
RunSysprepGeneralize      aws:runCommand          Pending    {}
StopInstance              aws:changeInstanceState Pending    {}
CreateImage               aws:createImage         Pending    {}
TerminateInstance         aws:changeInstanceState Pending    {}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetAutomationExecution](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAutomationExecutionList`
<a name="ssm_DescribeAutomationExecutions_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例描述与您的账户关联的所有活动和已终止的自动化执行。**  

```
Get-SSMAutomationExecutionList
```
**输出**：  

```
AutomationExecutionId     : 4105a4fc-f944-11e6-9d32-8fb2db27a909
AutomationExecutionStatus : Failed
DocumentName              : AWS-UpdateLinuxAmi
DocumentVersion           : 1
ExecutedBy                : admin
ExecutionEndTime          : 2/22/2017 9:17:08 PM
ExecutionStartTime        : 2/22/2017 9:17:02 PM
LogFile                   :
Outputs                   : {[createImage.ImageId, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]}
```
**示例 2：此示例显示了 “成功” 以 AutomationExecutionStatus 外的执行的 executionID、文档、执行 start/end 时间戳**  

```
Get-SSMAutomationExecutionList | Where-Object AutomationExecutionStatus -ne "Success" | Select-Object AutomationExecutionId, DocumentName, AutomationExecutionStatus, ExecutionStartTime, ExecutionEndTime | Format-Table -AutoSize
```
**输出**：  

```
AutomationExecutionId                DocumentName                            AutomationExecutionStatus ExecutionStartTime   ExecutionEndTime
---------------------                ------------                            ------------------------- ------------------   ----------------
e1d2bad3-4567-8901-ae23-456c7c8901be AWS-UpdateWindowsAmi                    Cancelled                 4/16/2019 5:37:04 AM 4/16/2019 5:47:29 AM
61234567-a7f8-90e1-2b34-567b8bf9012c Fixed-UpdateAmi                         Cancelled                 4/16/2019 5:33:04 AM 4/16/2019 5:40:15 AM
91234d56-7e89-0ac1-2aee-34ea5d6a7c89 AWS-UpdateWindowsAmi                    Failed                    4/16/2019 5:22:46 AM 4/16/2019 5:27:29 AM
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeAutomationExecutions](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAutomationStepExecution`
<a name="ssm_DescribeAutomationStepExecutions_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示有关自动化工作流中所有活动和已终止步骤执行的信息。**  

```
Get-SSMAutomationStepExecution -AutomationExecutionId e1d2bad3-4567-8901-ae23-456c7c8901be | Select-Object StepName, Action, StepStatus
```
**输出**：  

```
StepName                  Action                  StepStatus
--------                  ------                  ----------
LaunchInstance            aws:runInstances        Success
OSCompatibilityCheck      aws:runCommand          Success
RunPreUpdateScript        aws:runCommand          Success
UpdateEC2Config           aws:runCommand          Cancelled
UpdateSSMAgent            aws:runCommand          Pending
UpdateAWSPVDriver         aws:runCommand          Pending
UpdateAWSEnaNetworkDriver aws:runCommand          Pending
UpdateAWSNVMe             aws:runCommand          Pending
InstallWindowsUpdates     aws:runCommand          Pending
RunPostUpdateScript       aws:runCommand          Pending
RunSysprepGeneralize      aws:runCommand          Pending
StopInstance              aws:changeInstanceState Pending
CreateImage               aws:createImage         Pending
TerminateInstance         aws:changeInstanceState Pending
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeAutomationStepExecutions](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMAvailablePatch`
<a name="ssm_DescribeAvailablePatches_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取 MSRC 严重性为“严重”的、适用于 Windows Server 2012 的所有可用补丁。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$filter1 = @{Key="PRODUCT";Values=@("WindowsServer2012")}
$filter2 = @{Key="MSRC_SEVERITY";Values=@("Critical")}

Get-SSMAvailablePatch -Filter $filter1,$filter2
```
**输出**：  

```
Classification : SecurityUpdates
ContentUrl     : https://support.microsoft.com/en-us/kb/2727528
Description    : A security issue has been identified that could allow an unauthenticated remote attacker to compromise your system and gain control
                 over it. You can help protect your system by installing this update from Microsoft. After you install this update, you may have to
                 restart your system.
Id             : 1eb507be-2040-4eeb-803d-abc55700b715
KbNumber       : KB2727528
Language       : All
MsrcNumber     : MS12-072
MsrcSeverity   : Critical
Product        : WindowsServer2012
ProductFamily  : Windows
ReleaseDate    : 11/13/2012 6:00:00 PM
Title          : Security Update for Windows Server 2012 (KB2727528)
Vendor         : Microsoft
...
```
**示例 2：在 PowerShell 版本 2 中，必须使用 New-Object 来创建每个滤镜。**  

```
$filter1 = New-Object Amazon.SimpleSystemsManagement.Model.PatchOrchestratorFilter
$filter1.Key = "PRODUCT"
$filter1.Values = "WindowsServer2012"
$filter2 = New-Object Amazon.SimpleSystemsManagement.Model.PatchOrchestratorFilter
$filter2.Key = "MSRC_SEVERITY"
$filter2.Values = "Critical"

Get-SSMAvailablePatch -Filter $filter1,$filter2
```
**示例 3：此示例提取了过去 20 天内发布且适用于与 2019 年匹配 WindowsServer的商品的所有更新**  

```
Get-SSMAvailablePatch | Where-Object ReleaseDate -ge (Get-Date).AddDays(-20) | Where-Object Product -eq "WindowsServer2019" | Select-Object ReleaseDate, Product, Title
```
**输出**：  

```
ReleaseDate         Product           Title
-----------         -------           -----
4/9/2019 5:00:12 PM WindowsServer2019 2019-04 Security Update for Adobe Flash Player for Windows Server 2019 for x64-based Systems (KB4493478)
4/9/2019 5:00:06 PM WindowsServer2019 2019-04 Cumulative Update for Windows Server 2019 for x64-based Systems (KB4493509)
4/2/2019 5:00:06 PM WindowsServer2019 2019-03 Servicing Stack Update for Windows Server 2019 for x64-based Systems (KB4493510)
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeAvailablePatches](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMCommand`
<a name="ssm_ListCommands_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出请求的所有命令。**  

```
Get-SSMCommand
```
**输出**：  

```
CommandId          : 4b75a163-d39a-4d97-87c9-98ae52c6be35
Comment            : Apply association with id at update time: 4cc73e42-d5ae-4879-84f8-57e09c0efcd0
CompletedCount     : 1
DocumentName       : AWS-RefreshAssociation
ErrorCount         : 0
ExpiresAfter       : 2/24/2017 3:19:08 AM
InstanceIds        : {i-0cb2b964d3e14fd9f}
MaxConcurrency     : 50
MaxErrors          : 0
NotificationConfig : Amazon.SimpleSystemsManagement.Model.NotificationConfig
OutputS3BucketName :
OutputS3KeyPrefix  :
OutputS3Region     :
Parameters         : {[associationIds, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]}
RequestedDateTime  : 2/24/2017 3:18:08 AM
ServiceRole        :
Status             : Success
StatusDetails      : Success
TargetCount        : 1
Targets            : {}
```
**示例 2：此示例获取特定命令的状态。**  

```
Get-SSMCommand -CommandId "4b75a163-d39a-4d97-87c9-98ae52c6be35"
```
**示例 3：此示例检索 2019-04-01T00:00:00Z 之后调用的所有 SSM 命令**  

```
Get-SSMCommand -Filter @{Key="InvokedAfter";Value="2019-04-01T00:00:00Z"} | Select-Object CommandId, DocumentName, Status, RequestedDateTime | Sort-Object -Property RequestedDateTime -Descending
```
**输出**：  

```
CommandId                            DocumentName               Status    RequestedDateTime
---------                            ------------               ------    -----------------
edb1b23e-456a-7adb-aef8-90e-012ac34f AWS-RunPowerShellScript    Cancelled 4/16/2019 5:45:23 AM
1a2dc3fb-4567-890d-a1ad-234b5d6bc7d9 AWS-ConfigureAWSPackage    Success   4/6/2019 9:19:42 AM
12c3456c-7e90-4f12-1232-1234f5b67893 KT-Retrieve-Cloud-Type-Win Failed    4/2/2019 4:13:07 AM
fe123b45-240c-4123-a2b3-234bdd567ecf AWS-RunInspecChecks        Failed    4/1/2019 2:27:31 PM
1eb23aa4-567d-4123-12a3-4c1c2ab34561 AWS-RunPowerShellScript    Success   4/1/2019 1:05:55 PM
1c2f3bb4-ee12-4bc1-1a23-12345eea123e AWS-RunInspecChecks        Failed    4/1/2019 11:13:09 AM
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListCommands](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMCommandInvocation`
<a name="ssm_ListCommandInvocations_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出命令的所有调用。**  

```
Get-SSMCommandInvocation -CommandId "b8eac879-0541-439d-94ec-47a80d554f44" -Detail $true
```
**输出**：  

```
CommandId          : b8eac879-0541-439d-94ec-47a80d554f44
CommandPlugins     : {aws:runShellScript}
Comment            : IP config
DocumentName       : AWS-RunShellScript
InstanceId         : i-0cb2b964d3e14fd9f
InstanceName       :
NotificationConfig : Amazon.SimpleSystemsManagement.Model.NotificationConfig
RequestedDateTime  : 2/22/2017 8:13:16 PM
ServiceRole        :
StandardErrorUrl   :
StandardOutputUrl  :
Status             : Success
StatusDetails      : Success
TraceOutput        :
```
**示例 2：此示例列出了命令 ID e1eb2e3c-ed4c- CommandPlugins 5123-45c1-234f5612345f 的调用**  

```
Get-SSMCommandInvocation -CommandId e1eb2e3c-ed4c-5123-45c1-234f5612345f -Detail:$true | Select-Object -ExpandProperty CommandPlugins
```
**输出**：  

```
Name                   : aws:runPowerShellScript
Output                 : Completed 17.7 KiB/17.7 KiB (40.1 KiB/s) with 1 file(s) remainingdownload: s3://dd-aess-r-ctmer/KUMO.png to ..\..\programdata\KUMO.png
                         kumo available

OutputS3BucketName     :
OutputS3KeyPrefix      :
OutputS3Region         : eu-west-1
ResponseCode           : 0
ResponseFinishDateTime : 4/3/2019 11:53:23 AM
ResponseStartDateTime  : 4/3/2019 11:53:21 AM
StandardErrorUrl       :
StandardOutputUrl      :
Status                 : Success
StatusDetails          : Success
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListCommandInvocations](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMCommandInvocationDetail`
<a name="ssm_GetCommandInvocation_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示在实例上执行的命令的详细信息。**  

```
Get-SSMCommandInvocationDetail -InstanceId "i-0cb2b964d3e14fd9f" -CommandId "b8eac879-0541-439d-94ec-47a80d554f44"
```
**输出**：  

```
CommandId              : b8eac879-0541-439d-94ec-47a80d554f44
Comment                : IP config
DocumentName           : AWS-RunShellScript
ExecutionElapsedTime   : PT0.004S
ExecutionEndDateTime   : 2017-02-22T20:13:16.651Z
ExecutionStartDateTime : 2017-02-22T20:13:16.651Z
InstanceId             : i-0cb2b964d3e14fd9f
PluginName             : aws:runShellScript
ResponseCode           : 0
StandardErrorContent   :
StandardErrorUrl       :
StandardOutputContent  :
StandardOutputUrl      :
Status                 : Success
StatusDetails          : Success
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetCommandInvocation](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMComplianceItemList`
<a name="ssm_ListComplianceItems_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出给定资源 ID 和类型的合规性项目列表，筛选合规性类型为“关联”**  

```
Get-SSMComplianceItemList -ResourceId i-1a2caf345f67d0dc2 -ResourceType ManagedInstance -Filter @{Key="ComplianceType";Values="Association"}
```
**输出**：  

```
ComplianceType   : Association
Details          : {[DocumentName, AWS-GatherSoftwareInventory], [DocumentVersion, 1]}
ExecutionSummary : Amazon.SimpleSystemsManagement.Model.ComplianceExecutionSummary
Id               : 123a45a1-c234-1234-1245-67891236db4e
ResourceId       : i-1a2caf345f67d0dc2
ResourceType     : ManagedInstance
Severity         : UNSPECIFIED
Status           : COMPLIANT
Title            :
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListComplianceItems](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMComplianceSummaryList`
<a name="ssm_ListComplianceSummaries_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例返回所有合规性类型的合规和不合规资源的摘要数。**  

```
Get-SSMComplianceSummaryList
```
**输出**：  

```
ComplianceType CompliantSummary                                      NonCompliantSummary
-------------- ----------------                                      -------------------
FleetTotal     Amazon.SimpleSystemsManagement.Model.CompliantSummary Amazon.SimpleSystemsManagement.Model.NonCompliantSummary
Association    Amazon.SimpleSystemsManagement.Model.CompliantSummary Amazon.SimpleSystemsManagement.Model.NonCompliantSummary
Custom:InSpec  Amazon.SimpleSystemsManagement.Model.CompliantSummary Amazon.SimpleSystemsManagement.Model.NonCompliantSummary
Patch          Amazon.SimpleSystemsManagement.Model.CompliantSummary Amazon.SimpleSystemsManagement.Model.NonCompliantSummary
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListComplianceSummaries](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMConnectionStatus`
<a name="ssm_GetConnectionStatus_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例检索实例的 Session Manager 连接状态，以确定其是否已连接并准备好接收 Session Manager 连接。**  

```
Get-SSMConnectionStatus -Target i-0a1caf234f12d3dc4
```
**输出**：  

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

### `Get-SSMDefaultPatchBaseline`
<a name="ssm_GetDefaultPatchBaseline_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示默认补丁基准。**  

```
Get-SSMDefaultPatchBaseline
```
**输出**：  

```
arn:aws:ssm:us-west-2:123456789012:patchbaseline/pb-04fb4ae6142167966
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetDefaultPatchBaseline](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMDeployablePatchSnapshotForInstance`
<a name="ssm_GetDeployablePatchSnapshotForInstance_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示实例使用的补丁基准的当前快照。此命令必须使用实例凭证从实例运行。为确保其使用实例证书，该示例将 `Amazon.Runtime.InstanceProfileAWSCredentials` 对象传递给 Credentials 参数。**  

```
$credentials = [Amazon.Runtime.InstanceProfileAWSCredentials]::new()
Get-SSMDeployablePatchSnapshotForInstance -SnapshotId "4681775b-098f-4435-a956-0ef33373ac11" -InstanceId "i-0cb2b964d3e14fd9f" -Credentials $credentials
```
**输出**：  

```
InstanceId          SnapshotDownloadUrl
----------          -------------------
i-0cb2b964d3e14fd9f https://patch-baseline-snapshot-us-west-2.s3-us-west-2.amazonaws.com/853d0d3db0f0cafe...1692/4681775b-098f-4435...
```
**示例 2：此示例说明如何获取完整内容 SnapshotDownloadUrl。此命令必须使用实例凭证从实例运行。为确保其使用实例证书，该示例将 PowerShell 会话配置为使用`Amazon.Runtime.InstanceProfileAWSCredentials`对象。**  

```
Set-AWSCredential -Credential ([Amazon.Runtime.InstanceProfileAWSCredentials]::new())
(Get-SSMDeployablePatchSnapshotForInstance -SnapshotId "4681775b-098f-4435-a956-0ef33373ac11" -InstanceId "i-0cb2b964d3e14fd9f").SnapshotDownloadUrl
```
**输出**：  

```
https://patch-baseline-snapshot-us-west-2.s3-us-west-2.amazonaws.com/853d0d3db0f0cafe...
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetDeployablePatchSnapshotForInstance](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMDocument`
<a name="ssm_GetDocument_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例返回文档的内容。**  

```
Get-SSMDocument -Name "RunShellScript"
```
**输出**：  

```
Content
-------
{...
```
**示例 2：此示例显示文档的完整内容。**  

```
(Get-SSMDocument -Name "RunShellScript").Content
{
   "schemaVersion":"2.0",
   "description":"Run an updated script",
   "parameters":{
      "commands":{
         "type":"StringList",
         "description":"(Required) Specify a shell script or a command to run.",
         "minItems":1,
         "displayType":"textarea"
      }
   },
   "mainSteps":[
      {
         "action":"aws:runShellScript",
         "name":"runShellScript",
         "inputs":{
            "commands":"{{ commands }}"
         }
      },
      {
         "action":"aws:runPowerShellScript",
         "name":"runPowerShellScript",
         "inputs":{
            "commands":"{{ commands }}"
         }
      }
   ]
}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetDocument](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMDocumentDescription`
<a name="ssm_DescribeDocument_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例返回有关文档的信息。**  

```
Get-SSMDocumentDescription -Name "RunShellScript"
```
**输出**：  

```
CreatedDate     : 2/24/2017 5:25:13 AM
DefaultVersion  : 1
Description     : Run an updated script
DocumentType    : Command
DocumentVersion : 1
Hash            : f775e5df4904c6fa46686c4722fae9de1950dace25cd9608ff8d622046b68d9b
HashType        : Sha256
LatestVersion   : 1
Name            : RunShellScript
Owner           : 123456789012
Parameters      : {commands}
PlatformTypes   : {Linux}
SchemaVersion   : 2.0
Sha1            :
Status          : Active
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeDocument](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMDocumentList`
<a name="ssm_ListDocuments_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：列出您账户中的所有配置文档。**  

```
Get-SSMDocumentList
```
**输出**：  

```
DocumentType    : Command
DocumentVersion : 1
Name            : AWS-ApplyPatchBaseline
Owner           : Amazon
PlatformTypes   : {Windows}
SchemaVersion   : 1.2

DocumentType    : Command
DocumentVersion : 1
Name            : AWS-ConfigureAWSPackage
Owner           : Amazon
PlatformTypes   : {Windows, Linux}
SchemaVersion   : 2.0

DocumentType    : Command
DocumentVersion : 1
Name            : AWS-ConfigureCloudWatch
Owner           : Amazon
PlatformTypes   : {Windows}
SchemaVersion   : 1.2
...
```
**示例 2：此示例检索名称与“Platform”匹配的所有自动化文档**  

```
Get-SSMDocumentList -DocumentFilterList @{Key="DocumentType";Value="Automation"} | Where-Object Name -Match "Platform"
```
**输出**：  

```
DocumentFormat  : JSON
DocumentType    : Automation
DocumentVersion : 7
Name            : KT-Get-Platform
Owner           : 987654123456
PlatformTypes   : {Windows, Linux}
SchemaVersion   : 0.3
Tags            : {}
TargetType      :
VersionName     :
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListDocuments](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMDocumentPermission`
<a name="ssm_DescribeDocumentPermission_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出文档的所有版本。**  

```
Get-SSMDocumentVersionList -Name "RunShellScript"
```
**输出**：  

```
CreatedDate          DocumentVersion IsDefaultVersion Name
-----------          --------------- ---------------- ----
2/24/2017 5:25:13 AM 1               True             RunShellScript
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeDocumentPermission](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMDocumentVersionList`
<a name="ssm_ListDocumentVersions_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出文档的所有版本。**  

```
Get-SSMDocumentVersionList -Name "AWS-UpdateSSMAgent"
```
**输出**：  

```
CreatedDate       : 6/1/2021 5:19:10 PM
DocumentFormat    : JSON
DocumentVersion   : 1
IsDefaultVersion  : True
Name              : AWS-UpdateSSMAgent
Status            : Active
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListDocumentVersions](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMEffectiveInstanceAssociationList`
<a name="ssm_DescribeEffectiveInstanceAssociations_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例描述实例的有效关联。**  

```
Get-SSMEffectiveInstanceAssociationList -InstanceId "i-0000293ffd8c57862" -MaxResult 5
```
**输出**：  

```
AssociationId                        Content
-------------                        -------
d8617c07-2079-4c18-9847-1655fc2698b0 {...
```
**示例 2：此示例显示实例有效关联的内容。**  

```
(Get-SSMEffectiveInstanceAssociationList -InstanceId "i-0000293ffd8c57862" -MaxResult 5).Content
```
**输出**：  

```
{
    "schemaVersion": "1.2",
    "description": "Update the Amazon SSM Agent to the latest version or specified version.",
    "parameters": {
        "version": {
            "default": "",
            "description": "(Optional) A specific version of the Amazon SSM Agent to install. If not specified, the agen
t will be updated to the latest version.",
            "type": "String"
        },
        "allowDowngrade": {
            "default": "false",
            "description": "(Optional) Allow the Amazon SSM Agent service to be downgraded to an earlier version. If set
 to false, the service can be upgraded to newer versions only (default). If set to true, specify the earlier version.",
            "type": "String",
            "allowedValues": [
                "true",
                "false"
            ]
        }
    },
    "runtimeConfig": {
        "aws:updateSsmAgent": {
            "properties": [
                {
                "agentName": "amazon-ssm-agent",
                "source": "https://s3.{Region}.amazonaws.com/amazon-ssm-{Region}/ssm-agent-manifest.json",
                "allowDowngrade": "{{ allowDowngrade }}",
                "targetVersion": "{{ version }}"
                }
            ]
        }
    }
}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeEffectiveInstanceAssociations](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMEffectivePatchesForPatchBaseline`
<a name="ssm_DescribeEffectivePatchesForPatchBaseline_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出所有补丁基准，最大结果列表为 1。**  

```
Get-SSMEffectivePatchesForPatchBaseline -BaselineId "pb-0a2f1059b670ebd31" -MaxResult 1
```
**输出**：  

```
Patch                                      PatchStatus
-----                                      -----------
Amazon.SimpleSystemsManagement.Model.Patch Amazon.SimpleSystemsManagement.Model.PatchStatus
```
**示例 2：此示例显示所有补丁基准的补丁状态，最大结果列表为 1。**  

```
(Get-SSMEffectivePatchesForPatchBaseline -BaselineId "pb-0a2f1059b670ebd31" -MaxResult 1).PatchStatus
```
**输出**：  

```
ApprovalDate          DeploymentStatus
------------          ----------------
12/21/2010 6:00:00 PM APPROVED
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeEffectivePatchesForPatchBaseline](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMInstanceAssociationsStatus`
<a name="ssm_DescribeInstanceAssociationsStatus_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示实例关联的详细信息。**  

```
Get-SSMInstanceAssociationsStatus -InstanceId "i-0000293ffd8c57862"
```
**输出**：  

```
AssociationId    : d8617c07-2079-4c18-9847-1655fc2698b0
DetailedStatus   : Pending
DocumentVersion  : 1
ErrorCode        :
ExecutionDate    : 2/20/2015 8:31:11 AM
ExecutionSummary : temp_status_change
InstanceId       : i-0000293ffd8c57862
Name             : AWS-UpdateSSMAgent
OutputUrl        :
Status           : Pending
```
**示例 2：此示例检查给定实例 ID 的实例关联状态，并进一步显示这些关联的执行状态**  

```
Get-SSMInstanceAssociationsStatus -InstanceId i-012e3cb4df567e8aa | ForEach-Object {Get-SSMAssociationExecution -AssociationId .AssociationId}
```
**输出**：  

```
AssociationId         : 512a34a5-c678-1234-1234-12345678db9e
AssociationVersion    : 2
CreatedTime           : 3/2/2019 8:53:29 AM
DetailedStatus        :
ExecutionId           : 512a34a5-c678-1234-1234-12345678db9e
LastExecutionDate     : 1/1/0001 12:00:00 AM
ResourceCountByStatus : {Success=9}
Status                : Success
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeInstanceAssociationsStatus](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMInstanceInformation`
<a name="ssm_DescribeInstanceInformation_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示每个实例的详细信息。**  

```
Get-SSMInstanceInformation
```
**输出**：  

```
ActivationId                           :
AgentVersion                           : 2.0.672.0
AssociationOverview                    : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview
AssociationStatus                      : Success
ComputerName                           : ip-172-31-44-222.us-west-2.compute.internal
IamRole                                :
InstanceId                             : i-0cb2b964d3e14fd9f
IPAddress                              : 172.31.44.222
IsLatestVersion                        : True
LastAssociationExecutionDate           : 2/24/2017 3:18:09 AM
LastPingDateTime                       : 2/24/2017 3:35:03 AM
LastSuccessfulAssociationExecutionDate : 2/24/2017 3:18:09 AM
Name                                   :
PingStatus                             : ConnectionLost
PlatformName                           : Amazon Linux AMI
PlatformType                           : Linux
PlatformVersion                        : 2016.09
RegistrationDate                       : 1/1/0001 12:00:00 AM
ResourceType                           : EC2Instance
```
**示例 2：此示例说明如何使用-Filter 参数将结果筛选到区域`us-east-1`中仅为`AgentVersion`的`2.2.800.0`那些 AWS 系统管理器实例。你可以在 InstanceInformation API 参考主题 (https://docs.aws.amazon.com/systems-manager/latest/APIReference/API\$1 InstanceInformation .html \$1systemsmanager-Type--InstanceInformation) 中找到有效的-Filter 键值列表。ActivationId**  

```
$Filters = @{
    Key="AgentVersion"
    Values="2.2.800.0"
}
Get-SSMInstanceInformation -Region us-east-1 -Filter $Filters
```
**输出**：  

```
ActivationId                           : 
AgentVersion                           : 2.2.800.0
AssociationOverview                    : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview
AssociationStatus                      : Success
ComputerName                           : EXAMPLE-EXAMPLE.WORKGROUP
IamRole                                : 
InstanceId                             : i-EXAMPLEb0792d98ce
IPAddress                              : 10.0.0.01
IsLatestVersion                        : False
LastAssociationExecutionDate           : 8/16/2018 12:02:50 AM
LastPingDateTime                       : 8/16/2018 7:40:27 PM
LastSuccessfulAssociationExecutionDate : 8/16/2018 12:02:50 AM
Name                                   : 
PingStatus                             : Online
PlatformName                           : Microsoft Windows Server 2016 Datacenter
PlatformType                           : Windows
PlatformVersion                        : 10.0.14393
RegistrationDate                       : 1/1/0001 12:00:00 AM
ResourceType                           : EC2Instance

ActivationId                           : 
AgentVersion                           : 2.2.800.0
AssociationOverview                    : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview
AssociationStatus                      : Success
ComputerName                           : EXAMPLE-EXAMPLE.WORKGROUP
IamRole                                : 
InstanceId                             : i-EXAMPLEac7501d023
IPAddress                              : 10.0.0.02
IsLatestVersion                        : False
LastAssociationExecutionDate           : 8/16/2018 12:00:20 AM
LastPingDateTime                       : 8/16/2018 7:40:35 PM
LastSuccessfulAssociationExecutionDate : 8/16/2018 12:00:20 AM
Name                                   : 
PingStatus                             : Online
PlatformName                           : Microsoft Windows Server 2016 Datacenter
PlatformType                           : Windows
PlatformVersion                        : 10.0.14393
RegistrationDate                       : 1/1/0001 12:00:00 AM
ResourceType                           : EC2Instance
```
**示例 3：此示例说明如何使用-InstanceInformationFilterList 参数筛选结果，仅筛选区域中`us-east-1`带`Windows`或`PlatformTypes`的那些 AWS 系统管理器实例`Linux`。您可以在 InstanceInformationFilter API 参考主题 (https://docs.aws.amazon.com/systems-manager/latest/APIReference/API\$1 InstanceInformationFilter .html) 中找到有效的InstanceInformationFilterList 键值列表。**  

```
$Filters = @{
   Key="PlatformTypes"
   ValueSet=("Windows","Linux")
}
Get-SSMInstanceInformation -Region us-east-1 -InstanceInformationFilterList $Filters
```
**输出**：  

```
ActivationId                           : 
AgentVersion                           : 2.2.800.0
AssociationOverview                    : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview
AssociationStatus                      : Success
ComputerName                           : EXAMPLE-EXAMPLE.WORKGROUP
IamRole                                : 
InstanceId                             : i-EXAMPLEb0792d98ce
IPAddress                              : 10.0.0.27
IsLatestVersion                        : False
LastAssociationExecutionDate           : 8/16/2018 12:02:50 AM
LastPingDateTime                       : 8/16/2018 7:40:27 PM
LastSuccessfulAssociationExecutionDate : 8/16/2018 12:02:50 AM
Name                                   : 
PingStatus                             : Online
PlatformName                           : Ubuntu Server 18.04 LTS
PlatformType                           : Linux
PlatformVersion                        : 18.04
RegistrationDate                       : 1/1/0001 12:00:00 AM
ResourceType                           : EC2Instance

ActivationId                           : 
AgentVersion                           : 2.2.800.0
AssociationOverview                    : Amazon.SimpleSystemsManagement.Model.InstanceAggregatedAssociationOverview
AssociationStatus                      : Success
ComputerName                           : EXAMPLE-EXAMPLE.WORKGROUP
IamRole                                : 
InstanceId                             : i-EXAMPLEac7501d023
IPAddress                              : 10.0.0.100
IsLatestVersion                        : False
LastAssociationExecutionDate           : 8/16/2018 12:00:20 AM
LastPingDateTime                       : 8/16/2018 7:40:35 PM
LastSuccessfulAssociationExecutionDate : 8/16/2018 12:00:20 AM
Name                                   : 
PingStatus                             : Online
PlatformName                           : Microsoft Windows Server 2016 Datacenter
PlatformType                           : Windows
PlatformVersion                        : 10.0.14393
RegistrationDate                       : 1/1/0001 12:00:00 AM
ResourceType                           : EC2Instance
```
**示例 4：此示例列出了 ssm 托管实例以及导出 InstanceId PingStatus、 LastPingDateTime 和 PlatformName csv 文件。**  

```
Get-SSMInstanceInformation | Select-Object InstanceId, PingStatus, LastPingDateTime, PlatformName | Export-Csv Instance-details.csv -NoTypeInformation
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeInstanceInformation](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMInstancePatch`
<a name="ssm_DescribeInstancePatches_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取实例的补丁合规性详细信息。**  

```
Get-SSMInstancePatch -InstanceId "i-08ee91c0b17045407"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeInstancePatches](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMInstancePatchState`
<a name="ssm_DescribeInstancePatchStates_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取实例的补丁摘要状态。**  

```
Get-SSMInstancePatchState -InstanceId "i-08ee91c0b17045407"
```
**示例 2：此示例获取两个实例的补丁摘要状态。**  

```
Get-SSMInstancePatchState -InstanceId "i-08ee91c0b17045407","i-09a618aec652973a9"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeInstancePatchStates](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMInstancePatchStatesForPatchGroup`
<a name="ssm_DescribeInstancePatchStatesForPatchGroup_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取补丁组每个实例的补丁摘要状态。**  

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

### `Get-SSMInventory`
<a name="ssm_GetInventory_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取清单的自定义元数据。**  

```
Get-SSMInventory
```
**输出**：  

```
Data                                                                                  Id
----                                                                                  --
{[AWS:InstanceInformation, Amazon.SimpleSystemsManagement.Model.InventoryResultItem]} i-0cb2b964d3e14fd9f
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetInventory](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMInventoryEntriesList`
<a name="ssm_ListInventoryEntries_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出实例的所有自定义清单条目。**  

```
Get-SSMInventoryEntriesList -InstanceId "i-0cb2b964d3e14fd9f" -TypeName "Custom:RackInfo"
```
**输出**：  

```
CaptureTime   : 2016-08-22T10:01:01Z
Entries       : {Amazon.Runtime.Internal.Util.AlwaysSendDictionary`2[System.String,System.String]}
InstanceId    : i-0cb2b964d3e14fd9f
NextToken     :
SchemaVersion : 1.0
TypeName      : Custom:RackInfo
```
**示例 2：此示例列出详细信息。**  

```
(Get-SSMInventoryEntriesList -InstanceId "i-0cb2b964d3e14fd9f" -TypeName "Custom:RackInfo").Entries
```
**输出**：  

```
Key          Value
---          -----
RackLocation Bay B/Row C/Rack D/Shelf E
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListInventoryEntries](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMInventoryEntryList`
<a name="ssm_Get-SSMInventoryEntryList_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例检索实例的 `AWS:Network` 类型清单条目。**  

```
Get-SSMInventoryEntryList -InstanceId mi-088dcb0ecea37b076 -TypeName AWS:Network | Select-Object -ExpandProperty Entries
```
**输出**：  

```
Key        Value
---        -----
DHCPServer 172.31.11.2
DNSServer  172.31.0.1
Gateway    172.31.11.2
IPV4       172.31.11.222
IPV6       fe12::3456:7da8:901a:12a3
MacAddress 1A:23:4E:5B:FB:67
Name       Amazon Elastic Network Adapter
SubnetMask 255.255.240.0
```
+  有关 API 的详细信息，请参阅 [Get-SSMInventory EntryList in AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell/v4/reference) *Cmdlet 参考 (V4)*。

### `Get-SSMInventorySchema`
<a name="ssm_GetInventorySchema_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例返回账户清单类型名称列表。**  

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

### `Get-SSMLatestEC2Image`
<a name="ssm_Get-SSMLatestEC2Image_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出了所有最新的 Windows AMIs。**  

```
PS Get-SSMLatestEC2Image -Path ami-windows-latest
```
**输出**：  

```
Name                                                                    Value
----                                                                    -----
Windows_Server-2008-R2_SP1-English-64Bit-SQL_2012_SP4_Express           ami-0e5ddd288daff4fab
Windows_Server-2012-R2_RTM-Chinese_Simplified-64Bit-Base                ami-0c5ea64e6bec1cb50
Windows_Server-2012-R2_RTM-Chinese_Traditional-64Bit-Base               ami-09775eff0bf8c113d
Windows_Server-2012-R2_RTM-Dutch-64Bit-Base                             ami-025064b67e28cf5df
...
```
**示例 2：此示例检索 us-west-2 区域的特定 Amazon Linux 映像的 AMI ID。**  

```
PS Get-SSMLatestEC2Image -Path ami-amazon-linux-latest -ImageName amzn-ami-hvm-x86_64-ebs -Region us-west-2
```
**输出**：  

```
ami-09b92cd132204c704
```
**示例 3：此示例列出了所有与指定通配符表达式 AMIs 匹配的最新窗口。**  

```
Get-SSMLatestEC2Image -Path ami-windows-latest -ImageName *Windows*2019*English*
```
**输出**：  

```
Name                                                     Value
----                                                     -----
Windows_Server-2019-English-Full-SQL_2017_Web            ami-085e9d27da5b73a42
Windows_Server-2019-English-STIG-Core                    ami-0bfd85c29148c7f80
Windows_Server-2019-English-Full-SQL_2019_Web            ami-02099560d7fb11f20
Windows_Server-2019-English-Full-SQL_2016_SP2_Standard   ami-0d7ae2d81c07bd598
...
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考文档 (V* 4) 中的[获取SSMLatestEC2图片](https://docs.aws.amazon.com/powershell/v4/reference)。

### `Get-SSMMaintenanceWindow`
<a name="ssm_GetMaintenanceWindow_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取有关维护时段的详细信息。**  

```
Get-SSMMaintenanceWindow -WindowId "mw-03eb9db42890fb82d"
```
**输出**：  

```
AllowUnassociatedTargets : False
CreatedDate              : 2/20/2017 6:14:05 PM
Cutoff                   : 1
Duration                 : 2
Enabled                  : True
ModifiedDate             : 2/20/2017 6:14:05 PM
Name                     : TestMaintWin
Schedule                 : cron(0 */30 * * * ? *)
WindowId                 : mw-03eb9db42890fb82d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetMaintenanceWindow](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMMaintenanceWindowExecution`
<a name="ssm_GetMaintenanceWindowExecution_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出有关作为维护时段执行组成部分来执行的任务的信息。**  

```
Get-SSMMaintenanceWindowExecution -WindowExecutionId "518d5565-5969-4cca-8f0e-da3b2a638355"
```
**输出**：  

```
EndTime           : 2/21/2017 4:00:35 PM
StartTime         : 2/21/2017 4:00:34 PM
Status            : FAILED
StatusDetails     : One or more tasks in the orchestration failed.
TaskIds           : {ac0c6ae1-daa3-4a89-832e-d384503b6586}
WindowExecutionId : 518d5565-5969-4cca-8f0e-da3b2a638355
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetMaintenanceWindowExecution](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMMaintenanceWindowExecutionList`
<a name="ssm_DescribeMaintenanceWindowExecutions_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出维护时段的所有执行。**  

```
Get-SSMMaintenanceWindowExecutionList -WindowId "mw-03eb9db42890fb82d"
```
**输出**：  

```
EndTime           : 2/20/2017 6:30:17 PM
StartTime         : 2/20/2017 6:30:16 PM
Status            : FAILED
StatusDetails     : One or more tasks in the orchestration failed.
WindowExecutionId : 6f3215cf-4101-4fa0-9b7b-9523269599c7
WindowId          : mw-03eb9db42890fb82d
```
**示例 2：此示例列出在指定日期之前的维护时段内的所有执行。**  

```
$option1 = @{Key="ExecutedBefore";Values=@("2016-11-04T05:00:00Z")}
Get-SSMMaintenanceWindowExecutionList -WindowId "mw-03eb9db42890fb82d" -Filter $option1
```
**示例 3：此示例列出指定日期之后维护时段内的所有执行。**  

```
$option1 = @{Key="ExecutedAfter";Values=@("2016-11-04T05:00:00Z")}
Get-SSMMaintenanceWindowExecutionList -WindowId "mw-03eb9db42890fb82d" -Filter $option1
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeMaintenanceWindowExecutions](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMMaintenanceWindowExecutionTask`
<a name="ssm_GetMaintenanceWindowExecutionTask_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出有关维护时段执行组成部分的任务的信息。**  

```
Get-SSMMaintenanceWindowExecutionTask -TaskId "ac0c6ae1-daa3-4a89-832e-d384503b6586" -WindowExecutionId "518d5565-5969-4cca-8f0e-da3b2a638355"
```
**输出**：  

```
EndTime           : 2/21/2017 4:00:35 PM
MaxConcurrency    : 1
MaxErrors         : 1
Priority          : 10
ServiceRole       : arn:aws:iam::123456789012:role/MaintenanceWindowsRole
StartTime         : 2/21/2017 4:00:34 PM
Status            : FAILED
StatusDetails     : The maximum error count was exceeded.
TaskArn           : AWS-RunShellScript
TaskExecutionId   : ac0c6ae1-daa3-4a89-832e-d384503b6586
TaskParameters    : {Amazon.Runtime.Internal.Util.AlwaysSendDictionary`2[System.String,Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskPara
                    meterValueExpression]}
Type              : RUN_COMMAND
WindowExecutionId : 518d5565-5969-4cca-8f0e-da3b2a638355
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetMaintenanceWindowExecutionTask](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMMaintenanceWindowExecutionTaskInvocationList`
<a name="ssm_DescribeMaintenanceWindowExecutionTaskInvocations_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出作为维护时段执行组成部分来执行的任务的调用。**  

```
Get-SSMMaintenanceWindowExecutionTaskInvocationList -TaskId "ac0c6ae1-daa3-4a89-832e-d384503b6586" -WindowExecutionId "518d5565-5969-4cca-8f0e-da3b2a638355"
```
**输出**：  

```
EndTime           : 2/21/2017 4:00:34 PM
ExecutionId       :
InvocationId      : e274b6e1-fe56-4e32-bd2a-8073c6381d8b
OwnerInformation  :
Parameters        : {"documentName":"AWS-RunShellScript","instanceIds":["i-0000293ffd8c57862"],"parameters":{"commands":["df"]},"maxConcurrency":"1",
                    "maxErrors":"1"}
StartTime         : 2/21/2017 4:00:34 PM
Status            : FAILED
StatusDetails     : The instance IDs list contains an invalid entry.
TaskExecutionId   : ac0c6ae1-daa3-4a89-832e-d384503b6586
WindowExecutionId : 518d5565-5969-4cca-8f0e-da3b2a638355
WindowTargetId    :
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeMaintenanceWindowExecutionTaskInvocations](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMMaintenanceWindowExecutionTaskList`
<a name="ssm_DescribeMaintenanceWindowExecutionTasks_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出与维护时段执行相关的任务。**  

```
Get-SSMMaintenanceWindowExecutionTaskList -WindowExecutionId "518d5565-5969-4cca-8f0e-da3b2a638355"
```
**输出**：  

```
EndTime           : 2/21/2017 4:00:35 PM
StartTime         : 2/21/2017 4:00:34 PM
Status            : SUCCESS
TaskArn           : AWS-RunShellScript
TaskExecutionId   : ac0c6ae1-daa3-4a89-832e-d384503b6586
TaskType          : RUN_COMMAND
WindowExecutionId : 518d5565-5969-4cca-8f0e-da3b2a638355
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeMaintenanceWindowExecutionTasks](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMMaintenanceWindowList`
<a name="ssm_DescribeMaintenanceWindows_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出您账户中的所有维护时段。**  

```
Get-SSMMaintenanceWindowList
```
**输出**：  

```
Cutoff   : 1
Duration : 4
Enabled  : True
Name     : My-First-Maintenance-Window
WindowId : mw-06d59c1a07c022145
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeMaintenanceWindows](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMMaintenanceWindowTarget`
<a name="ssm_DescribeMaintenanceWindowTargets_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出维护时段的所有目标。**  

```
Get-SSMMaintenanceWindowTarget -WindowId "mw-06cf17cbefcb4bf4f"
```
**输出**：  

```
OwnerInformation : Single instance
ResourceType     : INSTANCE
Targets          : {InstanceIds}
WindowId         : mw-06cf17cbefcb4bf4f
WindowTargetId   : 350d44e6-28cc-44e2-951f-4b2c985838f6

OwnerInformation : Two instances in a list
ResourceType     : INSTANCE
Targets          : {InstanceIds}
WindowId         : mw-06cf17cbefcb4bf4f
WindowTargetId   : e078a987-2866-47be-bedd-d9cf49177d3a
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeMaintenanceWindowTargets](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMMaintenanceWindowTaskList`
<a name="ssm_DescribeMaintenanceWindowTasks_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出维护时段的所有任务。**  

```
Get-SSMMaintenanceWindowTaskList -WindowId "mw-06cf17cbefcb4bf4f"
```
**输出**：  

```
LoggingInfo    :
MaxConcurrency : 1
MaxErrors      : 1
Priority       : 10
ServiceRoleArn : arn:aws:iam::123456789012:role/MaintenanceWindowsRole
Targets        : {InstanceIds}
TaskArn        : AWS-RunShellScript
TaskParameters : {[commands, Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskParameterValueExpression]}
Type           : RUN_COMMAND
WindowId       : mw-06cf17cbefcb4bf4f
WindowTaskId   : a23e338d-ff30-4398-8aa3-09cd052ebf17
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeMaintenanceWindowTasks](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMParameterHistory`
<a name="ssm_GetParameterHistory_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出参数的值历史记录。**  

```
Get-SSMParameterHistory -Name "Welcome"
```
**输出**：  

```
Description      :
KeyId            :
LastModifiedDate : 3/3/2017 6:55:25 PM
LastModifiedUser : arn:aws:iam::123456789012:user/admin
Name             : Welcome
Type             : String
Value            : helloWorld
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetParameterHistory](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMParameterList`
<a name="ssm_DescribeParameters_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出所有参数。**  

```
Get-SSMParameterList
```
**输出**：  

```
Description      :
KeyId            :
LastModifiedDate : 3/3/2017 6:58:23 PM
LastModifiedUser : arn:aws:iam::123456789012:user/admin
Name             : Welcome
Type             : String
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeParameters](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMParameterValue`
<a name="ssm_GetParameters_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出参数的值。**  

```
Get-SSMParameterValue -Name "Welcome"
```
**输出**：  

```
InvalidParameters Parameters
----------------- ----------
{}                {Welcome}
```
**示例 2：此示例列出值的详细信息。**  

```
(Get-SSMParameterValue -Name "Welcome").Parameters
```
**输出**：  

```
Name    Type   Value
----    ----   -----
Welcome String Good day, Sunshine!
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetParameters](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMPatchBaseline`
<a name="ssm_DescribePatchBaselines_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出所有补丁基准。**  

```
Get-SSMPatchBaseline
```
**输出**：  

```
BaselineDescription                                             BaselineId                                                            BaselineName
-------------------                                             ----------                                                            ------------
Default Patch Baseline Provided by AWS.                         arn:aws:ssm:us-west-2:123456789012:patchbaseline/pb-04fb4ae6142167966 AWS-DefaultP...
Baseline containing all updates approved for production systems pb-045f10b4f382baeda                                                  Production-B...
Baseline containing all updates approved for production systems pb-0a2f1059b670ebd31                                                  Production-B...
```
**示例 2：此示例列出了提供的所有补丁基准。 AWS此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$filter1 = @{Key="OWNER";Values=@("AWS")}
```
**输出**：  

```
Get-SSMPatchBaseline -Filter $filter1
```
**示例 3：此示例列出您作为所有者的所有补丁基准。此示例使用的语法需要 PowerShell 版本 3 或更高版本。**  

```
$filter1 = @{Key="OWNER";Values=@("Self")}
```
**输出**：  

```
Get-SSMPatchBaseline -Filter $filter1
```
**示例 4：在 PowerShell 版本 2 中，必须使用 New-Object 来创建每个标签。**  

```
$filter1 = New-Object Amazon.SimpleSystemsManagement.Model.PatchOrchestratorFilter
$filter1.Key = "OWNER"
$filter1.Values = "AWS"

Get-SSMPatchBaseline -Filter $filter1
```
**输出**：  

```
BaselineDescription                     BaselineId                                                            BaselineName             DefaultBaselin
                                                                                                                                       e
-------------------                     ----------                                                            ------------             --------------
Default Patch Baseline Provided by AWS. arn:aws:ssm:us-west-2:123456789012:patchbaseline/pb-04fb4ae6142167966 AWS-DefaultPatchBaseline True
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribePatchBaselines](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMPatchBaselineDetail`
<a name="ssm_GetPatchBaseline_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示补丁基准的详细信息。**  

```
Get-SSMPatchBaselineDetail -BaselineId "pb-03da896ca3b68b639"
```
**输出**：  

```
ApprovalRules   : Amazon.SimpleSystemsManagement.Model.PatchRuleGroup
ApprovedPatches : {}
BaselineId      : pb-03da896ca3b68b639
CreatedDate     : 3/3/2017 5:02:19 PM
Description     : Baseline containing all updates approved for production systems
GlobalFilters   : Amazon.SimpleSystemsManagement.Model.PatchFilterGroup
ModifiedDate    : 3/3/2017 5:02:19 PM
Name            : Production-Baseline
PatchGroups     : {}
RejectedPatches : {}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetPatchBaseline](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMPatchBaselineForPatchGroup`
<a name="ssm_GetPatchBaselineForPatchGroup_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例显示补丁组的补丁基准。**  

```
Get-SSMPatchBaselineForPatchGroup -PatchGroup "Production"
```
**输出**：  

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

### `Get-SSMPatchGroup`
<a name="ssm_DescribePatchGroups_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出补丁组注册。**  

```
Get-SSMPatchGroup
```
**输出**：  

```
BaselineIdentity                                           PatchGroup
----------------                                           ----------
Amazon.SimpleSystemsManagement.Model.PatchBaselineIdentity Production
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribePatchGroups](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMPatchGroupState`
<a name="ssm_DescribePatchGroupState_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取补丁组的高级补丁合规性摘要。**  

```
Get-SSMPatchGroupState -PatchGroup "Production"
```
**输出**：  

```
Instances                          : 4
InstancesWithFailedPatches         : 1
InstancesWithInstalledOtherPatches : 4
InstancesWithInstalledPatches      : 3
InstancesWithMissingPatches        : 0
InstancesWithNotApplicablePatches  : 0
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribePatchGroupState](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMResourceComplianceSummaryList`
<a name="ssm_ListResourceComplianceSummaries_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取资源级摘要计数。摘要包含有关合规和不合规状态的信息以及与“Windows10”匹配产品的详细合规性项目严重性计数。由于如果未指定参数，则 MaxResult 默认值为 100，且此值无效，因此会添加 MaxResult 参数，并将该值设置为 50。**  

```
$FilterValues = @{
		"Key"="Product"
        "Type"="EQUAL"
        "Values"="Windows10"
}
        Get-SSMResourceComplianceSummaryList -Filter $FilterValues -MaxResult 50
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ListResourceComplianceSummaries](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Get-SSMResourceTag`
<a name="ssm_ListTagsForResource_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例列出维护时段的标签。**  

```
Get-SSMResourceTag -ResourceId "mw-03eb9db42890fb82d" -ResourceType "MaintenanceWindow"
```
**输出**：  

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

### `New-SSMActivation`
<a name="ssm_CreateActivation_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例创建托管式实例。**  

```
New-SSMActivation -DefaultInstanceName "MyWebServers" -IamRole "SSMAutomationRole" -RegistrationLimit 10
```
**输出**：  

```
ActivationCode       ActivationId
--------------       ------------
KWChhOxBTiwDcKE9BlKC 08e51e79-1e36-446c-8e63-9458569c1363
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateActivation](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `New-SSMAssociation`
<a name="ssm_CreateAssociation_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用实例将配置文档与实例关联起来 IDs。**  

```
New-SSMAssociation -InstanceId "i-0cb2b964d3e14fd9f" -Name "AWS-UpdateSSMAgent"
```
**输出**：  

```
Name                  : AWS-UpdateSSMAgent
InstanceId            : i-0000293ffd8c57862
Date                  : 2/23/2017 6:55:22 PM
Status.Name           : Associated
Status.Date           : 2/20/2015 8:31:11 AM
Status.Message        : Associated with AWS-UpdateSSMAgent
Status.AdditionalInfo :
```
**示例 2：此示例使用目标将配置文档与实例关联起来。**  

```
$target = @{Key="instanceids";Values=@("i-0cb2b964d3e14fd9f")}
New-SSMAssociation -Name "AWS-UpdateSSMAgent" -Target $target
```
**输出**：  

```
Name                  : AWS-UpdateSSMAgent
InstanceId            :
Date                  : 3/1/2017 6:22:21 PM
Status.Name           :
Status.Date           :
Status.Message        :
Status.AdditionalInfo :
```
**示例 3：此示例使用目标和参数将配置文档与实例关联起来。**  

```
$target = @{Key="instanceids";Values=@("i-0cb2b964d3e14fd9f")}
$params = @{
  "action"="configure"
  "mode"="ec2"
  "optionalConfigurationSource"="ssm"
  "optionalConfigurationLocation"=""
  "optionalRestart"="yes"
}
New-SSMAssociation -Name "Configure-CloudWatch" -AssociationName "CWConfiguration" -Target $target -Parameter $params
```
**输出**：  

```
Name                  : Configure-CloudWatch
InstanceId            :
Date                  : 5/17/2018 3:17:44 PM
Status.Name           :
Status.Date           :
Status.Message        :
Status.AdditionalInfo :
```
**示例 4：此示例使用 `AWS-GatherSoftwareInventory` 创建了与该区域中所有实例的关联。它还在要收集的参数中提供自定义文件和注册表位置**  

```
$params = [Collections.Generic.Dictionary[String,Collections.Generic.List[String]]]::new()
$params["windowsRegistry"] ='[{"Path":"HKEY_LOCAL_MACHINE\SOFTWARE\Amazon\MachineImage","Recursive":false,"ValueNames":["AMIName"]}]'
$params["files"] = '[{"Path":"C:\Program Files","Pattern":["*.exe"],"Recursive":true}, {"Path":"C:\ProgramData","Pattern":["*.log"],"Recursive":true}]' 
New-SSMAssociation -AssociationName new-in-mum -Name AWS-GatherSoftwareInventory -Target @{Key="instanceids";Values="*"} -Parameter $params -region ap-south-1 -ScheduleExpression "rate(720 minutes)"
```
**输出**：  

```
Name                  : AWS-GatherSoftwareInventory
InstanceId            :
Date                  : 6/9/2019 8:57:56 AM
Status.Name           :
Status.Date           :
Status.Message        :
Status.AdditionalInfo :
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateAssociation](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `New-SSMAssociationFromBatch`
<a name="ssm_CreateAssociationBatch_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例将一个配置文档与多个实例相关联。如果适用，输出将返回成功和失败操作的列表。**  

```
$option1 = @{InstanceId="i-0cb2b964d3e14fd9f";Name=@("AWS-UpdateSSMAgent")}
$option2 = @{InstanceId="i-0000293ffd8c57862";Name=@("AWS-UpdateSSMAgent")}
New-SSMAssociationFromBatch -Entry $option1,$option2
```
**输出**：  

```
Failed  Successful
------  ----------
{}      {Amazon.SimpleSystemsManagement.Model.FailedCreateAssociation, Amazon.SimpleSystemsManagement.Model.FailedCreateAsso...
```
**示例 2：此示例将显示成功操作的完整详细信息。**  

```
$option1 = @{InstanceId="i-0cb2b964d3e14fd9f";Name=@("AWS-UpdateSSMAgent")}
$option2 = @{InstanceId="i-0000293ffd8c57862";Name=@("AWS-UpdateSSMAgent")}
(New-SSMAssociationFromBatch -Entry $option1,$option2).Successful
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateAssociationBatch](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `New-SSMDocument`
<a name="ssm_CreateDocument_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例在您的账户中创建一个文档。该文档必须采用 JSON 格式。有关编写配置文档的更多信息，请参阅《SSM API Reference》中的配置文档。**  

```
New-SSMDocument -Content (Get-Content -Raw "c:\temp\RunShellScript.json") -Name "RunShellScript" -DocumentType "Command"
```
**输出**：  

```
CreatedDate     : 3/1/2017 1:21:33 AM
DefaultVersion  : 1
Description     : Run an updated script
DocumentType    : Command
DocumentVersion : 1
Hash            : 1d5ce820e999ff051eb4841ed887593daf77120fd76cae0d18a53cc42e4e22c1
HashType        : Sha256
LatestVersion   : 1
Name            : RunShellScript
Owner           : 809632081692
Parameters      : {commands}
PlatformTypes   : {Linux}
SchemaVersion   : 2.0
Sha1            :
Status          : Creating
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateDocument](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `New-SSMMaintenanceWindow`
<a name="ssm_CreateMaintenanceWindow_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用指定名称创建了一个新的维护时段，该时段在每周二下午 4 点运行 4 小时，中断 1 小时，且允许未关联的目标。**  

```
New-SSMMaintenanceWindow -Name "MyMaintenanceWindow" -Duration 4 -Cutoff 1 -AllowUnassociatedTarget $true -Schedule "cron(0 16 ? * TUE *)"
```
**输出**：  

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

### `New-SSMPatchBaseline`
<a name="ssm_CreatePatchBaseline_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例创建补丁基准，用于在 Microsoft 发布补丁 7 天后为在生产环境中运行 Windows Server 2019 的托管式实例批准补丁。**  

```
$rule = New-Object Amazon.SimpleSystemsManagement.Model.PatchRule
$rule.ApproveAfterDays = 7

$ruleFilters = New-Object Amazon.SimpleSystemsManagement.Model.PatchFilterGroup

$patchFilter = New-Object Amazon.SimpleSystemsManagement.Model.PatchFilter
$patchFilter.Key="PRODUCT"
$patchFilter.Values="WindowsServer2019"

$severityFilter = New-Object Amazon.SimpleSystemsManagement.Model.PatchFilter
$severityFilter.Key="MSRC_SEVERITY"
$severityFilter.Values.Add("Critical")
$severityFilter.Values.Add("Important")
$severityFilter.Values.Add("Moderate")

$classificationFilter = New-Object Amazon.SimpleSystemsManagement.Model.PatchFilter
$classificationFilter.Key = "CLASSIFICATION"
$classificationFilter.Values.Add( "SecurityUpdates" )
$classificationFilter.Values.Add( "Updates" )
$classificationFilter.Values.Add( "UpdateRollups" )
$classificationFilter.Values.Add( "CriticalUpdates" )

$ruleFilters.PatchFilters.Add($severityFilter)
$ruleFilters.PatchFilters.Add($classificationFilter)
$ruleFilters.PatchFilters.Add($patchFilter)
$rule.PatchFilterGroup = $ruleFilters

New-SSMPatchBaseline -Name "Production-Baseline-Windows2019" -Description "Baseline containing all updates approved for production systems" -ApprovalRules_PatchRule $rule
```
**输出**：  

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

### `Register-SSMDefaultPatchBaseline`
<a name="ssm_RegisterDefaultPatchBaseline_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例将补丁基准注册为默认补丁基准。**  

```
Register-SSMDefaultPatchBaseline -BaselineId "pb-03da896ca3b68b639"
```
**输出**：  

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

### `Register-SSMPatchBaselineForPatchGroup`
<a name="ssm_RegisterPatchBaselineForPatchGroup_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例为补丁组注册补丁基准。**  

```
Register-SSMPatchBaselineForPatchGroup -BaselineId "pb-03da896ca3b68b639" -PatchGroup "Production"
```
**输出**：  

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

### `Register-SSMTargetWithMaintenanceWindow`
<a name="ssm_RegisterTargetWithMaintenanceWindow_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例向维护时段注册实例。**  

```
$option1 = @{Key="InstanceIds";Values=@("i-0000293ffd8c57862")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Single instance" -ResourceType "INSTANCE"
```
**输出**：  

```
d8e47760-23ed-46a5-9f28-927337725398
```
**示例 2：此示例向维护时段注册多个实例。**  

```
$option1 = @{Key="InstanceIds";Values=@("i-0000293ffd8c57862","i-0cb2b964d3e14fd9f")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Single instance" -ResourceType "INSTANCE"
```
**输出**：  

```
6ab5c208-9fc4-4697-84b7-b02a6cc25f7d
```
**示例 3：此示例使用 EC2 标签向维护时段注册实例。**  

```
$option1 = @{Key="tag:Environment";Values=@("Production")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Production Web Servers" -ResourceType "INSTANCE"
```
**输出**：  

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

### `Register-SSMTaskWithMaintenanceWindow`
<a name="ssm_RegisterTaskWithMaintenanceWindow_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用实例 ID 向维护时段注册任务。输出为任务 ID。**  

```
$parameters = @{}
$parameterValues = New-Object Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskParameterValueExpression
$parameterValues.Values = @("Install")
$parameters.Add("Operation", $parameterValues)

Register-SSMTaskWithMaintenanceWindow -WindowId "mw-03a342e62c96d31b0" -ServiceRoleArn "arn:aws:iam::123456789012:role/MaintenanceWindowsRole" -MaxConcurrency 1 -MaxError 1 -TaskArn "AWS-RunShellScript" -Target @{ Key="InstanceIds";Values="i-0000293ffd8c57862" } -TaskType "RUN_COMMAND" -Priority 10 -TaskParameter $parameters
```
**输出**：  

```
f34a2c47-ddfd-4c85-a88d-72366b69af1b
```
**示例 2：此示例使用目标 ID 向维护时段注册任务。输出为任务 ID。**  

```
$parameters = @{}
$parameterValues = New-Object Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskParameterValueExpression
$parameterValues.Values = @("Install")
$parameters.Add("Operation", $parameterValues)

register-ssmtaskwithmaintenancewindow -WindowId "mw-03a342e62c96d31b0" -ServiceRoleArn "arn:aws:iam::123456789012:role/MaintenanceWindowsRole" -MaxConcurrency 1 -MaxError 1 -TaskArn "AWS-RunShellScript" -Target @{ Key="WindowTargetIds";Values="350d44e6-28cc-44e2-951f-4b2c985838f6" } -TaskType "RUN_COMMAND" -Priority 10 -TaskParameter $parameters
```
**输出**：  

```
f34a2c47-ddfd-4c85-a88d-72366b69af1b
```
**示例 3：此示例为运行命令文档 `AWS-RunPowerShellScript` 创建参数对象，并使用目标 ID 创建具有给定维护时段的任务。返回的输出是任务 ID。**  

```
$parameters = [Collections.Generic.Dictionary[String,Collections.Generic.List[String]]]::new()
$parameters.Add("commands",@("ipconfig","dir env:\computername"))
$parameters.Add("executionTimeout",@(3600))

$props = @{
    WindowId = "mw-0123e4cce56ff78ae"
    ServiceRoleArn = "arn:aws:iam::123456789012:role/MaintenanceWindowsRole"
    MaxConcurrency = 1
    MaxError = 1
    TaskType = "RUN_COMMAND"
    TaskArn = "AWS-RunPowerShellScript"
    Target = @{Key="WindowTargetIds";Values="fe1234ea-56d7-890b-12f3-456b789bee0f"}
    Priority = 1
    RunCommand_Parameter = $parameters
    Name = "set-via-cmdlet"
}

Register-SSMTaskWithMaintenanceWindow @props
```
**输出**：  

```
f1e2ef34-5678-12e3-456a-12334c5c6cbe
```
**示例 4：此示例使用名为的文档注册 AWS Systems Manager 自动化任务`Create-Snapshots`。**  

```
$automationParameters = @{}
$automationParameters.Add( "instanceId", @("{{ TARGET_ID }}") )
$automationParameters.Add( "AutomationAssumeRole", @("{arn:aws:iam::111111111111:role/AutomationRole}") )
$automationParameters.Add( "SnapshotTimeout", @("PT20M") )
Register-SSMTaskWithMaintenanceWindow -WindowId mw-123EXAMPLE456`
    -ServiceRoleArn "arn:aws:iam::123456789012:role/MW-Role"`
    -MaxConcurrency 1 -MaxError 1 -TaskArn "CreateVolumeSnapshots"`
    -Target @{ Key="WindowTargetIds";Values="4b5acdf4-946c-4355-bd68-4329a43a5fd1" }`
    -TaskType "AUTOMATION"`
    -Priority 4`
    -Automation_DocumentVersion '$DEFAULT' -Automation_Parameter $automationParameters -Name "Create-Snapshots"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [RegisterTaskWithMaintenanceWindow](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Remove-SSMActivation`
<a name="ssm_DeleteActivation_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除激活。如果此命令成功，则无任何输出。**  

```
Remove-SSMActivation -ActivationId "08e51e79-1e36-446c-8e63-9458569c1363"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeleteActivation](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Remove-SSMAssociation`
<a name="ssm_DeleteAssociation_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除实例和文档之间的关联。如果此命令成功，则无任何输出。**  

```
Remove-SSMAssociation -InstanceId "i-0cb2b964d3e14fd9f" -Name "AWS-UpdateSSMAgent"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeleteAssociation](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Remove-SSMDocument`
<a name="ssm_DeleteDocument_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除文档。如果此命令成功，则无任何输出。**  

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

### `Remove-SSMMaintenanceWindow`
<a name="ssm_DeleteMaintenanceWindow_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除维护时段。**  

```
Remove-SSMMaintenanceWindow -WindowId "mw-06d59c1a07c022145"
```
**输出**：  

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

### `Remove-SSMParameter`
<a name="ssm_DeleteParameter_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除一个参数。如果此命令成功，则无任何输出。**  

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

### `Remove-SSMPatchBaseline`
<a name="ssm_DeletePatchBaseline_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例删除补丁基准。**  

```
Remove-SSMPatchBaseline -BaselineId "pb-045f10b4f382baeda"
```
**输出**：  

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

### `Remove-SSMResourceTag`
<a name="ssm_RemoveTagsFromResource_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例从维护时段中删除标签。如果此命令成功，则无任何输出。**  

```
Remove-SSMResourceTag -ResourceId "mw-03eb9db42890fb82d" -ResourceType "MaintenanceWindow" -TagKey "Production"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [RemoveTagsFromResource](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Send-SSMCommand`
<a name="ssm_SendCommand_powershell_4_topic"></a>

以下代码示例演示了如何使用 `Send-SSMCommand`。

**适用于 PowerShell V4 的工具**  
**示例 1：此示例在目标实例上运行 echo 命令。**  

```
Send-SSMCommand -DocumentName "AWS-RunPowerShellScript" -Parameter @{commands = "echo helloWorld"} -Target @{Key="instanceids";Values=@("i-0cb2b964d3e14fd9f")}
```
**输出**：  

```
CommandId          : d8d190fc-32c1-4d65-a0df-ff5ff3965524
Comment            : 
CompletedCount     : 0
DocumentName       : AWS-RunPowerShellScript
ErrorCount         : 0
ExpiresAfter       : 3/7/2017 10:48:37 PM
InstanceIds        : {}
MaxConcurrency     : 50
MaxErrors          : 0
NotificationConfig : Amazon.SimpleSystemsManagement.Model.NotificationConfig
OutputS3BucketName : 
OutputS3KeyPrefix  : 
OutputS3Region     : 
Parameters         : {[commands, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]}
RequestedDateTime  : 3/7/2017 9:48:37 PM
ServiceRole        : 
Status             : Pending
StatusDetails      : Pending
TargetCount        : 0
Targets            : {instanceids}
```
**示例 2：此示例展示如何运行接受嵌套参数的命令。**  

```
Send-SSMCommand -DocumentName "AWS-RunRemoteScript" -Parameter @{ sourceType="GitHub";sourceInfo='{"owner": "me","repository": "amazon-ssm","path": "Examples/Install-Win32OpenSSH"}'; "commandLine"=".\Install-Win32OpenSSH.ps1"} -InstanceId i-0cb2b964d3e14fd9f
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [SendCommand](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Start-SSMAutomationExecution`
<a name="ssm_StartAutomationExecution_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例运行一个文档，指定自动化角色、AMI 源 ID 和 Amazon EC2 实例角色。**  

```
Start-SSMAutomationExecution -DocumentName AWS-UpdateLinuxAmi -Parameter @{'AutomationAssumeRole'='arn:aws:iam::123456789012:role/SSMAutomationRole';'SourceAmiId'='ami-f173cc91';'InstanceIamRole'='EC2InstanceRole'}
```
**输出**：  

```
3a532a4f-0382-11e7-9df7-6f11185f6dd1
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [StartAutomationExecution](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Start-SSMSession`
<a name="ssm_StartSession_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例为会话管理器会话启动与目标的连接，从而启用端口转发。**  

```
Start-SSMSession -Target 'i-064578e5e7454488f' -DocumentName 'AWS-StartPortForwardingSession' -Parameter @{ localPortNumber = '8080'; portNumber = '80' }
```
**输出**：  

```
SessionId    StreamUrl
----------    ----------
random-id0    wss://ssmmessages.amazonaws.com/v1/data-channel/random-id
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [StartSession](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Stop-SSMAutomationExecution`
<a name="ssm_StopAutomationExecution_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例停止自动化执行。如果此命令成功，则无任何输出。**  

```
Stop-SSMAutomationExecution -AutomationExecutionId "4105a4fc-f944-11e6-9d32-8fb2db27a909"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [StopAutomationExecution](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Stop-SSMCommand`
<a name="ssm_CancelCommand_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例尝试取消命令。如果操作成功，则无任何输出。**  

```
Stop-SSMCommand -CommandId "9ded293e-e792-4440-8e3e-7b8ec5feaa38"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CancelCommand](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Unregister-SSMManagedInstance`
<a name="ssm_DeregisterManagedInstance_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例取消注册托管式实例。如果此命令成功，则无任何输出。**  

```
Unregister-SSMManagedInstance -InstanceId "mi-08ab247cdf1046573"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeregisterManagedInstance](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Unregister-SSMPatchBaselineForPatchGroup`
<a name="ssm_DeregisterPatchBaselineForPatchGroup_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例从补丁基准中取消注册补丁组。**  

```
Unregister-SSMPatchBaselineForPatchGroup -BaselineId "pb-045f10b4f382baeda" -PatchGroup "Production"
```
**输出**：  

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

### `Unregister-SSMTargetFromMaintenanceWindow`
<a name="ssm_DeregisterTargetFromMaintenanceWindow_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例从维护时段中删除目标。**  

```
Unregister-SSMTargetFromMaintenanceWindow -WindowTargetId "6ab5c208-9fc4-4697-84b7-b02a6cc25f7d" -WindowId "mw-06cf17cbefcb4bf4f"
```
**输出**：  

```
WindowId             WindowTargetId
--------             --------------
mw-06cf17cbefcb4bf4f 6ab5c208-9fc4-4697-84b7-b02a6cc25f7d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeregisterTargetFromMaintenanceWindow](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Unregister-SSMTaskFromMaintenanceWindow`
<a name="ssm_DeregisterTaskFromMaintenanceWindow_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例从维护时段中删除任务。**  

```
Unregister-SSMTaskFromMaintenanceWindow -WindowTaskId "f34a2c47-ddfd-4c85-a88d-72366b69af1b" -WindowId "mw-03a342e62c96d31b0"
```
**输出**：  

```
WindowId             WindowTaskId
--------             ------------
mw-03a342e62c96d31b0 f34a2c47-ddfd-4c85-a88d-72366b69af1b
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DeregisterTaskFromMaintenanceWindow](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Update-SSMAssociation`
<a name="ssm_UpdateAssociation_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例使用新文档版本更新关联。**  

```
Update-SSMAssociation -AssociationId "93285663-92df-44cb-9f26-2292d4ecc439" -DocumentVersion "1"
```
**输出**：  

```
Name                  : AWS-UpdateSSMAgent
InstanceId            :
Date                  : 3/1/2017 6:22:21 PM
Status.Name           :
Status.Date           :
Status.Message        :
Status.AdditionalInfo :
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [UpdateAssociation](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Update-SSMAssociationStatus`
<a name="ssm_UpdateAssociationStatus_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例更新实例与配置文档之间关联的关联状态。**  

```
Update-SSMAssociationStatus -Name "AWS-UpdateSSMAgent" -InstanceId "i-0000293ffd8c57862" -AssociationStatus_Date "2015-02-20T08:31:11Z" -AssociationStatus_Name "Pending" -AssociationStatus_Message "temporary_status_change" -AssociationStatus_AdditionalInfo "Additional-Config-Needed"
```
**输出**：  

```
Name                  : AWS-UpdateSSMAgent
InstanceId            : i-0000293ffd8c57862
Date                  : 2/23/2017 6:55:22 PM
Status.Name           : Pending
Status.Date           : 2/20/2015 8:31:11 AM
Status.Message        : temporary_status_change
Status.AdditionalInfo : Additional-Config-Needed
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [UpdateAssociationStatus](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Update-SSMDocument`
<a name="ssm_UpdateDocument_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例将使用您指定的 json 文件更新内容创建文档的新版本。该文档必须采用 JSON 格式。您可以使用 “Get-SSMDocumentVersionList” cmdlet 获取文档版本。**  

```
Update-SSMDocument -Name RunShellScript -DocumentVersion "1" -Content (Get-Content -Raw "c:\temp\RunShellScript.json")
```
**输出**：  

```
CreatedDate     : 3/1/2017 2:59:17 AM
DefaultVersion  : 1
Description     : Run an updated script
DocumentType    : Command
DocumentVersion : 2
Hash            : 1d5ce820e999ff051eb4841ed887593daf77120fd76cae0d18a53cc42e4e22c1
HashType        : Sha256
LatestVersion   : 2
Name            : RunShellScript
Owner           : 809632081692
Parameters      : {commands}
PlatformTypes   : {Linux}
SchemaVersion   : 2.0
Sha1            :
Status          : Updating
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [UpdateDocument](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Update-SSMDocumentDefaultVersion`
<a name="ssm_UpdateDocumentDefaultVersion_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此实例更新文档的默认版本。您可以通过 “Get-SSMDocumentVersionList” cmdlet 获取可用的文档版本。**  

```
Update-SSMDocumentDefaultVersion -Name "RunShellScript" -DocumentVersion "2"
```
**输出**：  

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

### `Update-SSMMaintenanceWindow`
<a name="ssm_UpdateMaintenanceWindow_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例更新维护时段的名称。**  

```
Update-SSMMaintenanceWindow -WindowId "mw-03eb9db42890fb82d" -Name "My-Renamed-MW"
```
**输出**：  

```
AllowUnassociatedTargets : False
Cutoff                   : 1
Duration                 : 2
Enabled                  : True
Name                     : My-Renamed-MW
Schedule                 : cron(0 */30 * * * ? *)
WindowId                 : mw-03eb9db42890fb82d
```
**示例 2：此示例启用维护时段。**  

```
Update-SSMMaintenanceWindow -WindowId "mw-03eb9db42890fb82d" -Enabled $true
```
**输出**：  

```
AllowUnassociatedTargets : False
Cutoff                   : 1
Duration                 : 2
Enabled                  : True
Name                     : My-Renamed-MW
Schedule                 : cron(0 */30 * * * ? *)
WindowId                 : mw-03eb9db42890fb82d
```
**示例 3：此示例禁用维护时段。**  

```
Update-SSMMaintenanceWindow -WindowId "mw-03eb9db42890fb82d" -Enabled $false
```
**输出**：  

```
AllowUnassociatedTargets : False
Cutoff                   : 1
Duration                 : 2
Enabled                  : False
Name                     : My-Renamed-MW
Schedule                 : cron(0 */30 * * * ? *)
WindowId                 : mw-03eb9db42890fb82d
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [UpdateMaintenanceWindow](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Update-SSMManagedInstanceRole`
<a name="ssm_UpdateManagedInstanceRole_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例更新托管式实例的角色。如果此命令成功，则无任何输出。**  

```
Update-SSMManagedInstanceRole -InstanceId "mi-08ab247cdf1046573" -IamRole "AutomationRole"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [UpdateManagedInstanceRole](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Update-SSMPatchBaseline`
<a name="ssm_UpdatePatchBaseline_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例将两个补丁（作为已拒绝的补丁）和一个补丁（作为已批准的补丁）添加到现有补丁基准。**  

```
Update-SSMPatchBaseline -BaselineId "pb-03da896ca3b68b639" -RejectedPatch "KB2032276","MS10-048" -ApprovedPatch "KB2124261"
```
**输出**：  

```
ApprovalRules   : Amazon.SimpleSystemsManagement.Model.PatchRuleGroup
ApprovedPatches : {KB2124261}
BaselineId      : pb-03da896ca3b68b639
CreatedDate     : 3/3/2017 5:02:19 PM
Description     : Baseline containing all updates approved for production systems
GlobalFilters   : Amazon.SimpleSystemsManagement.Model.PatchFilterGroup
ModifiedDate    : 3/3/2017 5:22:10 PM
Name            : Production-Baseline
RejectedPatches : {KB2032276, MS10-048}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [UpdatePatchBaseline](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Write-SSMComplianceItem`
<a name="ssm_PutComplianceItems_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例为给定的托管式实例编写自定义合规性项目**  

```
$item = [Amazon.SimpleSystemsManagement.Model.ComplianceItemEntry]::new()
$item.Id = "07Jun2019-3"
$item.Severity="LOW"
$item.Status="COMPLIANT"
$item.Title="Fin-test-1 - custom"
Write-SSMComplianceItem -ResourceId mi-012dcb3ecea45b678 -ComplianceType Custom:VSSCompliant2 -ResourceType ManagedInstance -Item $item -ExecutionSummary_ExecutionTime "07-Jun-2019"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [PutComplianceItems](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Write-SSMInventory`
<a name="ssm_PutInventory_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例将机架位置信息分配给某个实例。如果此命令成功，则无任何输出。**  

```
$data = New-Object "System.Collections.Generic.Dictionary[System.String,System.String]"
$data.Add("RackLocation", "Bay B/Row C/Rack D/Shelf F")

$items = New-Object "System.Collections.Generic.List[System.Collections.Generic.Dictionary[System.String, System.String]]"
$items.Add($data)

$customInventoryItem = New-Object Amazon.SimpleSystemsManagement.Model.InventoryItem
$customInventoryItem.CaptureTime = "2016-08-22T10:01:01Z"
$customInventoryItem.Content = $items
$customInventoryItem.TypeName = "Custom:TestRackInfo2"
$customInventoryItem.SchemaVersion = "1.0"

$inventoryItems = @($customInventoryItem)

Write-SSMInventory -InstanceId "i-0cb2b964d3e14fd9f" -Item $inventoryItems
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [PutInventory](https://docs.aws.amazon.com/powershell/v4/reference)中的。

### `Write-SSMParameter`
<a name="ssm_PutParameter_powershell_4_topic"></a>

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例创建一个参数。如果此命令成功，则无任何输出。**  

```
Write-SSMParameter -Name "Welcome" -Type "String" -Value "helloWorld"
```
**示例 2：此示例更改了参数。如果此命令成功，则无任何输出。**  

```
Write-SSMParameter -Name "Welcome" -Type "String" -Value "Good day, Sunshine!" -Overwrite $true
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [PutParameter](https://docs.aws.amazon.com/powershell/v4/reference)中的。