

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

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

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

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

# 使用 Tools for PowerShell V5 的 Amazon Cognito 身分範例
<a name="powershell_cognito-identity_code_examples"></a>

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

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

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

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

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

### `Get-CGIIdentityPool`
<a name="cognito-identity_DescribeIdentityPool_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：依照特定身分集區 ID 順序擷取其相關資訊。**  

```
Get-CGIIdentityPool -IdentityPoolId us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1
```
**輸出：**  

```
LoggedAt                       : 8/12/2015 4:29:40 PM
AllowUnauthenticatedIdentities : True
DeveloperProviderName          :
IdentityPoolId                 : us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1
IdentityPoolName               : CommonTests1
OpenIdConnectProviderARNs      : {}
SupportedLoginProviders        : {}
ResponseMetadata               : Amazon.Runtime.ResponseMetadata
ContentLength                  : 142
HttpStatusCode                 : OK
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeIdentityPool](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-CGIIdentityPoolList`
<a name="cognito-identity_ListIdentityPools_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：擷取現有身分集區的清單。**  

```
Get-CGIIdentityPoolList
```
**輸出：**  

```
IdentityPoolId                                                     IdentityPoolName
--------------                                                     ----------------
us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1                     CommonTests1
us-east-1:118d242d-204e-4b88-b803-EXAMPLEGUID2                     Tests2
us-east-1:15d49393-ab16-431a-b26e-EXAMPLEGUID3                     CommonTests13
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListIdentityPools](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-CGIIdentityPoolRole`
<a name="cognito-identity_GetIdentityPoolRoles_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：取得特定身分集區角色的相關資訊。**  

```
Get-CGIIdentityPoolRole -IdentityPoolId us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1
```
**輸出：**  

```
LoggedAt         : 8/12/2015 4:33:51 PM
IdentityPoolId   : us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1
Roles            : {[unauthenticated, arn:aws:iam::123456789012:role/CommonTests1Role]}
ResponseMetadata : Amazon.Runtime.ResponseMetadata
ContentLength    : 165
HttpStatusCode   : OK
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetIdentityPoolRoles](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-CGIIdentityPool`
<a name="cognito-identity_CreateIdentityPool_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：建立新的身分集區，該身分集區允許未驗證的身分。**  

```
New-CGIIdentityPool -AllowUnauthenticatedIdentities $true -IdentityPoolName CommonTests13
```
**輸出：**  

```
LoggedAt                       : 8/12/2015 4:56:07 PM
AllowUnauthenticatedIdentities : True
DeveloperProviderName          :
IdentityPoolId                 : us-east-1:15d49393-ab16-431a-b26e-EXAMPLEGUID3
IdentityPoolName               : CommonTests13
OpenIdConnectProviderARNs      : {}
SupportedLoginProviders        : {}
ResponseMetadata               : Amazon.Runtime.ResponseMetadata
ContentLength                  : 136
HttpStatusCode                 : OK
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateIdentityPool](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-CGIIdentityPool`
<a name="cognito-identity_DeleteIdentityPool_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：刪除特定身分集區。**  

```
Remove-CGIIdentityPool -IdentityPoolId us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteIdentityPool](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-CGIIdentityPoolRole`
<a name="cognito-identity_SetIdentityPoolRoles_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：將特定身分集區設定為具有未驗證的 IAM 角色。**  

```
Set-CGIIdentityPoolRole -IdentityPoolId us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1 -Role @{ "unauthenticated" = "arn:aws:iam::123456789012:role/CommonTests1Role" }
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [SetIdentityPoolRoles](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Update-CGIIdentityPool`
<a name="cognito-identity_UpdateIdentityPool_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：更新一些身分集區屬性，在此案例為身分集區的名稱。**  

```
Update-CGIIdentityPool -IdentityPoolId us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1 -IdentityPoolName NewPoolName
```
**輸出：**  

```
LoggedAt                       : 8/12/2015 4:53:33 PM
AllowUnauthenticatedIdentities : False
DeveloperProviderName          :
IdentityPoolId                 : us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1
IdentityPoolName               : NewPoolName
OpenIdConnectProviderARNs      : {}
SupportedLoginProviders        : {}
ResponseMetadata               : Amazon.Runtime.ResponseMetadata
ContentLength                  : 135
HttpStatusCode                 : OK
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateIdentityPool](https://docs.aws.amazon.com/powershell/v5/reference)。