有谁知道如何使用 AWS Powershell 获取 AWS 帐号?看起来没有可用的 API。
问问题
3899 次
4 回答
8
漂亮又简单
(Get-STSCallerIdentity).Account
...或者
(Get-STSCallerIdentity -Region [your_aws_region]).Account
于 2019-11-19T13:58:31.373 回答
1
我无法对提供的其他答案发表评论,因此我必须提供自己的解决方案作为轻微修改。
我确实相信所有组上的 OwnerId 都将是 Account Id。但是,您可能没有“默认”组。我建议省略 -GroupNames “默认”。此外,我使用 SAML 令牌展示了我的示例,因为这是我们使用 AD 授权的情况。
$awsAccountNumber = (get-ec2securitygroup -ProfileName saml -Region us-west-2)[0].OwnerId
希望这会有一些用处。
于 2018-03-08T00:22:13.523 回答
0
我使用 Get-STSCallerIdentity。
这是我使用的代码片段:
foreach ($ProfileName in $Profiles){
if ($ProfileName -match 'gov') {
Initialize-AWSDefaultConfiguration -ProfileName $ProfileName -Region us-gov-east-1
$STSCallerIdentity = Get-STSCallerIdentity
}
else {
Initialize-AWSDefaultConfiguration -ProfileName $ProfileName -Region us-east-1
$STSCallerIdentity = Get-STSCallerIdentity
}
于 2019-08-20T12:27:57.207 回答