

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

# 将 `DescribeImageAttribute` 与 CLI 配合使用
<a name="example_ec2_DescribeImageAttribute_section"></a>

以下代码示例演示如何使用 `DescribeImageAttribute`。

------
#### [ CLI ]

**AWS CLI**  
**描述 AMI 的启动权限**  
此示例描述了指定 AMI 的启动权限。  
命令:  

```
aws ec2 describe-image-attribute --image-id ami-5731123e --attribute launchPermission
```
输出：  

```
{
    "LaunchPermissions": [
        {
            "UserId": "123456789012"
        }
    ],
    "ImageId": "ami-5731123e",
}
```
**描述 AMI 的产品代码**  
此示例描述了指定 AMI 的产品代码。请注意，此 AMI 没有产品代码。  
命令:  

```
aws ec2 describe-image-attribute --image-id ami-5731123e --attribute productCodes
```
输出：  

```
{
    "ProductCodes": [],
    "ImageId": "ami-5731123e",
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeImageAttribute](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/describe-image-attribute.html)*中的。

------
#### [ PowerShell ]

**适用于 PowerShell V4 的工具**  
**示例 1：此示例获取指定 AMI 的描述。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute description
```
**输出**：  

```
BlockDeviceMappings : {}
Description         : My image description
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     :
```
**示例 2：此示例描述指定 AMI 的启动权限。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission
```
**输出**：  

```
BlockDeviceMappings : {}
Description         :
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {all}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     :
```
**示例 3：此示例测试是否启用增强联网。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute sriovNetSupport
```
**输出**：  

```
BlockDeviceMappings : {}
Description         :
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     : simple
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [DescribeImageAttribute](https://docs.aws.amazon.com/powershell/v4/reference)中的。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例获取指定 AMI 的描述。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute description
```
**输出**：  

```
BlockDeviceMappings : {}
Description         : My image description
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     :
```
**示例 2：此示例描述指定 AMI 的启动权限。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission
```
**输出**：  

```
BlockDeviceMappings : {}
Description         :
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {all}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     :
```
**示例 3：此示例测试是否启用增强联网。**  

```
Get-EC2ImageAttribute -ImageId ami-12345678 -Attribute sriovNetSupport
```
**输出**：  

```
BlockDeviceMappings : {}
Description         :
ImageId             : ami-12345678
KernelId            :
LaunchPermissions   : {}
ProductCodes        : {}
RamdiskId           :
SriovNetSupport     : simple
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeImageAttribute](https://docs.aws.amazon.com/powershell/v5/reference)中的。

------

有关 S AWS DK 开发者指南和代码示例的完整列表，请参阅[使用 AWS SDK 创建 Amazon EC2 资源](sdk-general-information-section.md)。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。