

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

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

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

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

# AWS Cloud9 使用 Tools for PowerShell V5 的範例
<a name="powershell_cloud9_code_examples"></a>

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

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

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

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

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

### `Get-C9EnvironmentData`
<a name="cloud9_DescribeEnvironments_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定 AWS Cloud9 開發環境的相關資訊。**  

```
Get-C9EnvironmentData -EnvironmentId 685f892f431b45c2b28cb69eadcdb0EX,1980b80e5f584920801c09086667f0EX
```
**輸出：**  

```
Arn         : arn:aws:cloud9:us-east-1:123456789012:environment:685f892f431b45c2b28cb69eadcdb0EX
Description : Created from CodeStar.
Id          : 685f892f431b45c2b28cb69eadcdb0EX
Lifecycle   : Amazon.Cloud9.Model.EnvironmentLifecycle
Name        : my-demo-ec2-env
OwnerArn    : arn:aws:iam::123456789012:user/MyDemoUser
Type        : ec2

Arn         : arn:aws:cloud9:us-east-1:123456789012:environment:1980b80e5f584920801c09086667f0EX
Description :
Id          : 1980b80e5f584920801c09086667f0EX
Lifecycle   : Amazon.Cloud9.Model.EnvironmentLifecycle
Name        : my-demo-ssh-env
OwnerArn    : arn:aws:iam::123456789012:user/MyDemoUser
Type        : ssh
```
**範例 2：此範例會取得指定 AWS Cloud9 開發環境生命週期狀態的相關資訊。**  

```
(Get-C9EnvironmentData -EnvironmentId 685f892f431b45c2b28cb69eadcdb0EX).Lifecycle
```
**輸出：**  

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

### `Get-C9EnvironmentList`
<a name="cloud9_ListEnvironments_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會取得 available AWS Cloud9 開發環境識別符的清單。**  

```
Get-C9EnvironmentList
```
**輸出：**  

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

### `Get-C9EnvironmentMembershipList`
<a name="cloud9_DescribeEnvironmentMemberships_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定 AWS Cloud9 開發環境的環境成員相關資訊。**  

```
Get-C9EnvironmentMembershipList -EnvironmentId ffd88420d4824eeeaeaa8a04bfde8cEX
```
**輸出：**  

```
EnvironmentId : ffd88420d4824eeeaeaa8a04bfde8cEX
LastAccess    : 1/1/0001 12:00:00 AM
Permissions   : read-write
UserArn       : arn:aws:iam::123456789012:user/AnotherDemoUser
UserId        : AIDAJ3BA6O2FMJWCWXHEX

EnvironmentId : ffd88420d4824eeeaeaa8a04bfde8cEX
LastAccess    : 1/1/0001 12:00:00 AM
Permissions   : owner
UserArn       : arn:aws:iam::123456789012:user/MyDemoUser
UserId        : AIDAJ3LOROMOUXTBSU6EX
```
**範例 2：此範例取得有關指定 AWS Cloud9 開發環境擁有者的資訊。**  

```
Get-C9EnvironmentMembershipList -EnvironmentId ffd88420d4824eeeaeaa8a04bfde8cEX -Permission owner
```
**輸出：**  

```
EnvironmentId : ffd88420d4824eeeaeaa8a04bfde8cEX
LastAccess    : 1/1/0001 12:00:00 AM
Permissions   : owner
UserArn       : arn:aws:iam::123456789012:user/MyDemoUser
UserId        : AIDAJ3LOROMOUXTBSU6EX
```
**範例 3：此範例取得多個 AWS Cloud9 開發環境之指定環境成員的相關資訊。**  

```
Get-C9EnvironmentMembershipList -UserArn arn:aws:iam::123456789012:user/MyDemoUser
```
**輸出：**  

```
EnvironmentId : ffd88420d4824eeeaeaa8a04bfde8cEX
LastAccess    : 1/17/2018 7:48:14 PM
Permissions   : owner
UserArn       : arn:aws:iam::123456789012:user/MyDemoUser
UserId        : AIDAJ3LOROMOUXTBSU6EX

EnvironmentId : 1980b80e5f584920801c09086667f0EX
LastAccess    : 1/16/2018 11:21:24 PM
Permissions   : owner
UserArn       : arn:aws:iam::123456789012:user/MyDemoUser
UserId        : AIDAJ3LOROMOUXTBSU6EX
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeEnvironmentMemberships](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-C9EnvironmentStatus`
<a name="cloud9_DescribeEnvironmentStatus_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定 AWS Cloud9 開發環境的狀態資訊。**  

```
Get-C9EnvironmentStatus -EnvironmentId 349c86d4579e4e7298d500ff57a6b2EX
```
**輸出：**  

```
Message                     Status
-------                     ------
Environment is ready to use ready
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeEnvironmentStatus](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-C9EnvironmentEC2`
<a name="cloud9_CreateEnvironmentEc2_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會使用指定的設定建立 an AWS Cloud9 開發環境、啟動 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體，然後從執行個體連線至環境。**  

```
New-C9EnvironmentEC2 -Name my-demo-env -AutomaticStopTimeMinutes 60 -Description "My demonstration development environment." -InstanceType t2.micro -OwnerArn arn:aws:iam::123456789012:user/MyDemoUser -SubnetId subnet-d43a46EX
```
**輸出：**  

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

### `New-C9EnvironmentMembership`
<a name="cloud9_CreateEnvironmentMembership_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的環境成員新增至指定的 AWS Cloud9 開發環境。**  

```
New-C9EnvironmentMembership -UserArn arn:aws:iam::123456789012:user/AnotherDemoUser -EnvironmentId ffd88420d4824eeeaeaa8a04bfde8cEX -Permission read-write
```
**輸出：**  

```
EnvironmentId : ffd88420d4824eeeaeaa8a04bfde8cEX
LastAccess    : 1/1/0001 12:00:00 AM
Permissions   : read-write
UserArn       : arn:aws:iam::123456789012:user/AnotherDemoUser
UserId        : AIDAJ3BA6O2FMJWCWXHEX
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateEnvironmentMembership](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-C9Environment`
<a name="cloud9_DeleteEnvironment_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會刪除指定的 AWS Cloud9 開發環境。如果 Amazon EC2 執行個體連線至環境，該執行個體也會終止。**  

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

### `Remove-C9EnvironmentMembership`
<a name="cloud9_DeleteEnvironmentMembership_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會從指定的 AWS Cloud9 開發環境刪除指定的環境成員。**  

```
Remove-C9EnvironmentMembership -UserArn arn:aws:iam::123456789012:user/AnotherDemoUser -EnvironmentId ffd88420d4824eeeaeaa8a04bfde8cEX
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteEnvironmentMembership](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Update-C9Environment`
<a name="cloud9_UpdateEnvironment_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會變更指定之 existing AWS Cloud9 開發環境的指定設定。**  

```
Update-C9Environment -EnvironmentId ffd88420d4824eeeaeaa8a04bfde8cEX -Description "My changed demonstration development environment." -Name my-changed-demo-env
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateEnvironment](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Update-C9EnvironmentMembership`
<a name="cloud9_UpdateEnvironmentMembership_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會變更指定 AWS Cloud9 開發環境之指定現有環境成員的設定。**  

```
Update-C9EnvironmentMembership -UserArn arn:aws:iam::123456789012:user/AnotherDemoUser -EnvironmentId ffd88420d4824eeeaeaa8a04bfde8cEX -Permission read-only
```
**輸出：**  

```
EnvironmentId : ffd88420d4824eeeaeaa8a04bfde8cEX
LastAccess    : 1/1/0001 12:00:00 AM
Permissions   : read-only
UserArn       : arn:aws:iam::123456789012:user/AnotherDemoUser
UserId        : AIDAJ3BA6O2FMJWCWXHEX
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateEnvironmentMembership](https://docs.aws.amazon.com/powershell/v5/reference)。