

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

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

# 使用适用于 V5 的工具的 Amazon Cognito 身份示例 PowerShell
<a name="powershell_cognito-identity_code_examples"></a>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

**适用于 PowerShell V5 的工具**  
**示例 1：删除特定身份池。**  

```
Remove-CGIIdentityPool -IdentityPoolId us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteIdentityPool](https://docs.aws.amazon.com/powershell/v5/reference)中的。

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

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

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

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

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

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