

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

# 使用 AWS Systems Manager 自動化新增或更新 Windows 登錄項目
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager"></a>

*Appasaheb Bagali，Amazon Web Services*

## 總結
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-summary"></a>

AWS Systems Manager 是 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體的遠端管理工具。Systems Manager 提供對 Amazon Web Services 上基礎設施的可見性和控制。此多用途工具可用來修正安全性漏洞掃描報告識別為漏洞的 Windows 登錄檔變更。 

此模式涵蓋透過自動化基於環境安全而建議的登錄檔變更，來保護執行 Windows 作業系統之 EC2 執行個體安全的步驟。模式使用 Run 命令來執行 Command 文件。程式碼已連接，一部分包含在*程式碼*區段中。

## 先決條件和限制
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-prereqs"></a>
+ 作用中的 AWS 帳戶
+ 存取 EC2 執行個體和 Systems Manager 的許可

## Architecture
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-architecture"></a>

**目標技術堆疊**
+ 具有兩個子網路和網路位址轉譯 (NAT) 閘道的虛擬私有雲端 (VPC)
+ 用於新增或更新登錄檔名稱和值的 Systems Manager 命令文件
+ Systems Manager Run Command 在指定的 EC2 執行個體上執行命令文件

**目標架構**

![如何使用 AWS Systems Manager 自動新增或更新 Windows 登錄項目。](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2ecf680d-9f36-4070-8a19-2af262db7fcc/images/c992bcb0-d894-4aa7-9bb3-3d60c9c79e8d.png)


 

## 工具
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-tools"></a>

**工具**
+ [IAM 政策和角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) – AWS Identity and Access Management (IAM) 是一種 Web 服務，可協助您安全地控制對 AWS 資源的存取。您可以使用 IAM 來控制能通過身分驗證 (登入) 和授權使用資源的 (具有許可) 的人員。
+ [Amazon Simple Storage Service](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) – Amazon Simple Storage Service (Amazon S3) 是網際網路的儲存體。此服務旨在降低開發人員進行網路規模運算的難度。在此模式中，會使用 S3 儲存貯體來存放 Systems Manager 日誌。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) – AWS Systems Manager 是一種 AWS 服務，可用來檢視和控制 AWS 上的基礎設施。Systems Manager 透過掃描受*管執行個體*並報告 （或對其採取修正動作） 偵測到的任何政策違規，協助您維護安全性和合規性。
+ [AWS Systems Manager Command 文件](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-ssm-docs.html) – Run Command 會使用 AWS Systems Manager Command 文件。Systems Manager 支援的所有 Linux 和 Windows Server 作業系統都支援大多數命令文件。
+ [AWS Systems Manager Run Command](https://docs.aws.amazon.com/systems-manager/latest/userguide/execute-remote-commands.html) – AWS Systems Manager Run Command 可讓您從遠端安全地管理受管執行個體的組態。您可以使用 Run Command 自動化常見的管理任務，並大規模執行一次性組態變更。

**Code**

您可以使用下列範例程式碼，將 Microsoft Windows 登錄檔名稱新增至 或更新，將`Version`登錄檔路徑新增至 `HKCU:\Software\ScriptingGuys\Scripts`，並將值新增至 `2`。

```
#Windows registry path which needs to add/update
$registryPath ='HKCU:\\Software\\ScriptingGuys\\Scripts'
#Windows registry Name  which needs to add/update
$Name = 'Version'
#Windows registry value  which needs to add/update
$value = 2
# Test-Path cmdlet to see if the registry key exists. 
IF(!(Test-Path $registryPath))
        {
           New-Item -Path $registryPath -Force | Out-Null
           New-ItemProperty -Path $registryPath -Name $name -Value     $value ` -PropertyType DWORD -                 Force | Out-        Null 
        } ELSE {
                      New-ItemProperty -Path $registryPath -Name $name -Value $value ` -PropertyType            DWORD        -Force | Out-Null
            }
echo 'Registry Path:'$registryPath
 echo 'Registry Name:'$registryPath
 echo 'Registry Value:'(Get-ItemProperty -Path $registryPath -Name $Name).version
```

連接完整的 Systems Manager 命令文件 JavaScript 物件標記法 (JSON) 程式碼範例。 

## 史詩
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-epics"></a>

### 設定 VPC
<a name="set-up-a-vpc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 VPC。 | 在 AWS 管理主控台上，建立具有公有和私有子網路和 NAT 閘道的 VPC。如需詳細資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/batch/latest/userguide/create-public-private-vpc.html)。 | 雲端管理員 | 
| 建立安全群組。 | 確保每個安全群組允許從來源 IP 地址存取遠端桌面通訊協定 (RDP)。 | 雲端管理員 | 

### 建立 IAM 政策和 IAM 角色
<a name="create-an-iam-policy-and-an-iam-role"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 IAM 政策。 | 建立可讓您存取 Amazon S3、Amazon EC2 和 Systems Manager 的 IAM 政策。 | 雲端管理員 | 
| 建立 IAM 角色。 | 建立 IAM 角色，並連接提供 Amazon S3、Amazon EC2 和 Systems Manager 存取權的 IAM 政策。 | 雲端管理員 | 

### 執行自動化
<a name="run-the-automation"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Systems Manager 命令文件。 | 建立 Systems Manager Command 文件，以部署要新增或更新的 Microsoft Windows 登錄檔變更。 | 雲端管理員 | 
| 執行 Systems Manager Run Command。 | 執行 Systems Manager Run Command，選取 Command 文件和 Systems Manager 目標執行個體。這會將所選命令文件中的 Microsoft Windows 登錄檔變更推送到目標執行個體。 | 雲端管理員 | 

## 相關資源
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-resources"></a>
+ [AWS Systems Manager](https://aws.amazon.com/systems-manager/)
+ [AWS Systems Manager 文件](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-ssm-docs.html)
+ [AWS Systems Manager 執行命令](https://docs.aws.amazon.com/systems-manager/latest/userguide/execute-remote-commands.html)

## 附件
<a name="attachments-2ecf680d-9f36-4070-8a19-2af262db7fcc"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/2ecf680d-9f36-4070-8a19-2af262db7fcc/attachments/attachment.zip)