

的版本 5 (V5) Amazon Tools for PowerShell 已经发布！

有关重大更改和迁移应用程序的信息，请参阅[迁移主题](https://docs.amazonaws.cn/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.amazonaws.cn/powershell/v5/userguide/migrating-v5.html](https://docs.amazonaws.cn/powershell/v5/userguide/migrating-v5.html)

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

# 在 cmd ClientConfig let 中使用参数
<a name="pstools-clientconfig"></a>

当您连接到某个服务时，`ClientConfig` 参数可用于指定某些配置设置。此参数的大多数可能属性都是在类中定义的，该[https://docs.amazonaws.cn/sdkfornet/v3/apidocs/items/Runtime/TClientConfig.html](https://docs.amazonaws.cn/sdkfornet/v3/apidocs/items/Runtime/TClientConfig.html)类继承到 for serv Amazon ices 中。 APIs 有关简单继承的示例，请参阅 [https://docs.amazonaws.cn/sdkfornet/v3/apidocs/items/Keyspaces/TKeyspacesConfig.html](https://docs.amazonaws.cn/sdkfornet/v3/apidocs/items/Keyspaces/TKeyspacesConfig.html) 类。此外，一些服务定义了仅适用于该服务的附加属性。有关已定义的其他属性的示例，请参阅 [https://docs.amazonaws.cn/sdkfornet/v3/apidocs/items/S3/TS3Config.html](https://docs.amazonaws.cn/sdkfornet/v3/apidocs/items/S3/TS3Config.html) 类，特别是 `ForcePathStyle` 属性。

## 使用 `ClientConfig` 参数
<a name="clientconfig-operation"></a>

要使用该`ClientConfig`参数，可以在命令行上将其指定为`ClientConfig`对象，也可以使用 PowerShell splatting 将一组参数值作为一个单元传递给命令。以下示例中显示了这些方法。这些示例假设已安装并导入 `AWS.Tools.S3` 模块，并且您拥有具有适当权限的 `[default]` 凭据配置文件。

******定义一个 `ClientConfig` 对象**

```
$s3Config = New-Object -TypeName Amazon.S3.AmazonS3Config
$s3Config.ForcePathStyle = $true
$s3Config.Timeout = [TimeSpan]::FromMilliseconds(150000)
Get-S3Object -BucketName <BUCKET_NAME> -ClientConfig $s3Config
```

**使用 PowerShell飞溅添加`ClientConfig`属性**

```
$params=@{
    ClientConfig=@{
        ForcePathStyle=$true
        Timeout=[TimeSpan]::FromMilliseconds(150000)
    }
    BucketName="<BUCKET_NAME>"
}

Get-S3Object @params
```

## 使用未定义的属性
<a name="clientconfig-undefined"></a>

使用 PowerShell splatting 时，如果您指定的`ClientConfig`属性不存在，则要等到运行时才会检测到错误，此时它会返回异常。 Amazon Tools for PowerShell 修改上面的示例：

```
$params=@{
    ClientConfig=@{
        ForcePathStyle=$true
        UndefinedProperty="Value"
        Timeout=[TimeSpan]::FromMilliseconds(150000)
    }
    BucketName="<BUCKET_NAME>"
}

Get-S3Object @params
```

此示例生成类似以下内容的例外：

```
Cannot bind parameter 'ClientConfig'. Cannot create object of type "Amazon.S3.AmazonS3Config". The UndefinedProperty property was not found for the Amazon.S3.AmazonS3Config object.
```

## 指定 Amazon Web Services 区域
<a name="clientconfig-region"></a>

您可以使用`ClientConfig`参数 Amazon Web Services 区域 为命令设置。区域是通过 `RegionEndpoint` 属性设置的。根据以下优先级 Amazon Tools for PowerShell 计算要使用的区域：

1. `-Region` 参数

1. `ClientConfig` 参数中传递的区域

1. 会 PowerShell 话状态

1. 共享的 Amazon `config`文件

1. 环境变量

1. Amazon EC2 实例元数据（如果已启用）。