コマンドレットの検出とエイリアス - AWS Tools for PowerShell

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

コマンドレットの検出とエイリアス

このセクションでは、AWS Tools for PowerShell でサポートされているサービスを一覧表示する方法、これらのサービスをサポートするために AWS Tools for PowerShell から提供されているコマンドレットのセットを表示する方法、これらのサービスにアクセスするための代替のコマンドレット名 (エイリアスとも呼ばれます) を見つける方法について説明します。

コマンドレットの検出

すべての AWS サービスオペレーション (または API) は、各サービスの API リファレンスガイドに記載されています。例えば、「IAM API リファレンス」を参照してください。ほとんどの場合、AWS サービス API と AWS PowerShell コマンドレット間には 1 対 1 の対応があります。AWS サービスの API 名に対応するコマンドレット名を取得するには-ApiOperation、 パラメータと AWS サービスの API 名を指定して AWS Get-AWSCmdletName コマンドレットを呼び出します。例えば、利用可能なすべての DescribeInstances AWS サービスの API に基づくすべてのコマンドレット名を取得するには、次のコマンドを実行します。

PS > Get-AWSCmdletName -ApiOperation DescribeInstances CmdletName ServiceOperation ServiceName CmdletNounPrefix ---------- ---------------- ----------- ---------------- Get-EC2Instance DescribeInstances Amazon Elastic Compute Cloud EC2 Get-GMLInstance DescribeInstances Amazon GameLift Service GML

-ApiOperation パラメータはデフォルトのパラメータなので、パラメータ名は省略できます。次の例は、前の例と同等です。

PS > Get-AWSCmdletName DescribeInstances

API とサービスの両方の名前がわかっている場合は、コマンドレット名プレフィックスまたは AWS サービス名の一部と -Service パラメータを含めることができます たとえば、Amazon EC2 のコマンドレット名プレフィックスは EC2 です。Amazon EC2 サービスの DescribeInstances API に対応するコマンドレット名を取得するには、以下のいずれかのコマンドを実行します。どのコマンドでも同じ出力になります。

PS > Get-AWSCmdletName -ApiOperation DescribeInstances -Service EC2 PS > Get-AWSCmdletName -ApiOperation DescribeInstances -Service Compute PS > Get-AWSCmdletName -ApiOperation DescribeInstances -Service "Compute Cloud" CmdletName ServiceOperation ServiceName CmdletNounPrefix ---------- ---------------- ----------- ---------------- Get-EC2Instance DescribeInstances Amazon Elastic Compute Cloud EC2

これらのコマンドのパラメータ値では、大文字と小文字が区別されません。

使用する AWS サービス API または AWS サービスの名前がわからない場合は、マッチングパターンおよび -MatchWithRegex パラメータとともに -ApiOperation パラメータを使用できます。たとえば、SecurityGroup を含むすべてのコマンドレット名を取得するには、次のコマンドを実行します。

PS > Get-AWSCmdletName -ApiOperation SecurityGroup -MatchWithRegex CmdletName ServiceOperation ServiceName CmdletNounPrefix ---------- ---------------- ----------- ---------------- Approve-ECCacheSecurityGroupIngress AuthorizeCacheSecurityGroupIngress Amazon ElastiCache EC Get-ECCacheSecurityGroup DescribeCacheSecurityGroups Amazon ElastiCache EC New-ECCacheSecurityGroup CreateCacheSecurityGroup Amazon ElastiCache EC Remove-ECCacheSecurityGroup DeleteCacheSecurityGroup Amazon ElastiCache EC Revoke-ECCacheSecurityGroupIngress RevokeCacheSecurityGroupIngress Amazon ElastiCache EC Add-EC2SecurityGroupToClientVpnTargetNetwrk ApplySecurityGroupsToClientVpnTargetNetwork Amazon Elastic Compute Cloud EC2 Get-EC2SecurityGroup DescribeSecurityGroups Amazon Elastic Compute Cloud EC2 Get-EC2SecurityGroupReference DescribeSecurityGroupReferences Amazon Elastic Compute Cloud EC2 Get-EC2StaleSecurityGroup DescribeStaleSecurityGroups Amazon Elastic Compute Cloud EC2 Grant-EC2SecurityGroupEgress AuthorizeSecurityGroupEgress Amazon Elastic Compute Cloud EC2 Grant-EC2SecurityGroupIngress AuthorizeSecurityGroupIngress Amazon Elastic Compute Cloud EC2 New-EC2SecurityGroup CreateSecurityGroup Amazon Elastic Compute Cloud EC2 Remove-EC2SecurityGroup DeleteSecurityGroup Amazon Elastic Compute Cloud EC2 Revoke-EC2SecurityGroupEgress RevokeSecurityGroupEgress Amazon Elastic Compute Cloud EC2 Revoke-EC2SecurityGroupIngress RevokeSecurityGroupIngress Amazon Elastic Compute Cloud EC2 Update-EC2SecurityGroupRuleEgressDescription UpdateSecurityGroupRuleDescriptionsEgress Amazon Elastic Compute Cloud EC2 Update-EC2SecurityGroupRuleIngressDescription UpdateSecurityGroupRuleDescriptionsIngress Amazon Elastic Compute Cloud EC2 Edit-EFSMountTargetSecurityGroup ModifyMountTargetSecurityGroups Amazon Elastic File System EFS Get-EFSMountTargetSecurityGroup DescribeMountTargetSecurityGroups Amazon Elastic File System EFS Join-ELBSecurityGroupToLoadBalancer ApplySecurityGroupsToLoadBalancer Elastic Load Balancing ELB Set-ELB2SecurityGroup SetSecurityGroups Elastic Load Balancing V2 ELB2 Enable-RDSDBSecurityGroupIngress AuthorizeDBSecurityGroupIngress Amazon Relational Database Service RDS Get-RDSDBSecurityGroup DescribeDBSecurityGroups Amazon Relational Database Service RDS New-RDSDBSecurityGroup CreateDBSecurityGroup Amazon Relational Database Service RDS Remove-RDSDBSecurityGroup DeleteDBSecurityGroup Amazon Relational Database Service RDS Revoke-RDSDBSecurityGroupIngress RevokeDBSecurityGroupIngress Amazon Relational Database Service RDS Approve-RSClusterSecurityGroupIngress AuthorizeClusterSecurityGroupIngress Amazon Redshift RS Get-RSClusterSecurityGroup DescribeClusterSecurityGroups Amazon Redshift RS New-RSClusterSecurityGroup CreateClusterSecurityGroup Amazon Redshift RS Remove-RSClusterSecurityGroup DeleteClusterSecurityGroup Amazon Redshift RS Revoke-RSClusterSecurityGroupIngress RevokeClusterSecurityGroupIngress Amazon Redshift RS

AWS サービスの名前はわかるが、AWS サービス API の名前がわからない場合は、-MatchWithRegex パラメータと -Service パラメータを追加して、検索範囲を単一のサービスに絞り込みます。たとえば、Amazon EC2 サービス内のみで、SecurityGroup を含むすべてのコマンドレット名を取得するには、次のコマンドを実行します。

PS > Get-AWSCmdletName -ApiOperation SecurityGroup -MatchWithRegex -Service EC2 CmdletName ServiceOperation ServiceName CmdletNounPrefix ---------- ---------------- ----------- ---------------- Add-EC2SecurityGroupToClientVpnTargetNetwrk ApplySecurityGroupsToClientVpnTargetNetwork Amazon Elastic Compute Cloud EC2 Get-EC2SecurityGroup DescribeSecurityGroups Amazon Elastic Compute Cloud EC2 Get-EC2SecurityGroupReference DescribeSecurityGroupReferences Amazon Elastic Compute Cloud EC2 Get-EC2StaleSecurityGroup DescribeStaleSecurityGroups Amazon Elastic Compute Cloud EC2 Grant-EC2SecurityGroupEgress AuthorizeSecurityGroupEgress Amazon Elastic Compute Cloud EC2 Grant-EC2SecurityGroupIngress AuthorizeSecurityGroupIngress Amazon Elastic Compute Cloud EC2 New-EC2SecurityGroup CreateSecurityGroup Amazon Elastic Compute Cloud EC2 Remove-EC2SecurityGroup DeleteSecurityGroup Amazon Elastic Compute Cloud EC2 Revoke-EC2SecurityGroupEgress RevokeSecurityGroupEgress Amazon Elastic Compute Cloud EC2 Revoke-EC2SecurityGroupIngress RevokeSecurityGroupIngress Amazon Elastic Compute Cloud EC2 Update-EC2SecurityGroupRuleEgressDescription UpdateSecurityGroupRuleDescriptionsEgress Amazon Elastic Compute Cloud EC2 Update-EC2SecurityGroupRuleIngressDescription UpdateSecurityGroupRuleDescriptionsIngress Amazon Elastic Compute Cloud EC2

AWS Command Line Interface (AWS CLI) コマンドの名前がわかっている場合は、-AwsCliCommand パラメータと希望する AWS CLI コマンド名を使用して、同じ API に基づくコマンドレット名を取得します。例えば、Amazon EC2 サービスの authorize-security-group-ingress AWS CLI コマンド呼び出しに対応するコマンドレット名を取得するには、次のコマンドを実行します。

PS > Get-AWSCmdletName -AwsCliCommand "aws ec2 authorize-security-group-ingress" CmdletName ServiceOperation ServiceName CmdletNounPrefix ---------- ---------------- ----------- ---------------- Grant-EC2SecurityGroupIngress AuthorizeSecurityGroupIngress Amazon Elastic Compute Cloud EC2

Get-AWSCmdletName コマンドレットには、サービスと AWS API を特定できる AWS CLI コマンド名の一部を指定すれば十分です。

Tools for PowerShell Core のすべてのコマンドレットを一覧表示するには、次の例に示すように PowerShell Get-Command コマンドレットを実行します。

PS > Get-Command -Module AWSPowerShell.NetCore

-Module AWSPowerShell で同じコマンドを実行すると、AWS Tools for Windows PowerShell でコマンドレットを確認できます。

Get-Command コマンドレットは、コマンドレットをアルファベット順に一覧表示します。デフォルトでは、リストは PowerShell 名詞ではなく、PowerShell 動詞によってソートされます。

代わりに、サービスによって結果をソートするには、次のコマンドを実行します。

PS > Get-Command -Module AWSPowerShell.NetCore | Sort-Object Noun,Verb

Get-Command コマンドレットから返されたコマンドレットをフィルタリングするには、PowerShell の Select-String コマンドレットを実行します。たとえば、AWS リージョンを使用するコマンドレットのセットを表示するには、次のコマンドを実行します。

PS > Get-Command -Module AWSPowerShell.NetCore | Select-String region Clear-DefaultAWSRegion Copy-HSM2BackupToRegion Get-AWSRegion Get-DefaultAWSRegion Get-EC2Region Get-LSRegionList Get-RDSSourceRegion Set-DefaultAWSRegion

コマンドレット名詞のサービスプレフィックスでフィルタすることで特定のサービスのコマンドレットを見つけることもできます。使用可能なサービスプレフィックスのリストを表示するには、Get-AWSPowerShellVersion -ListServiceVersionInfo を実行します。次の例では、Amazon CloudWatch Events サービスをサポートするコマンドレットが返されます。

PS > Get-Command -Module AWSPowerShell -Noun CWE* CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Add-CWEResourceTag 3.3.563.1 AWSPowerShell.NetCore Cmdlet Disable-CWEEventSource 3.3.563.1 AWSPowerShell.NetCore Cmdlet Disable-CWERule 3.3.563.1 AWSPowerShell.NetCore Cmdlet Enable-CWEEventSource 3.3.563.1 AWSPowerShell.NetCore Cmdlet Enable-CWERule 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWEEventBus 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWEEventBusList 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWEEventSource 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWEEventSourceList 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWEPartnerEventSource 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWEPartnerEventSourceAccountList 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWEPartnerEventSourceList 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWEResourceTag 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWERule 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWERuleDetail 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWERuleNamesByTarget 3.3.563.1 AWSPowerShell.NetCore Cmdlet Get-CWETargetsByRule 3.3.563.1 AWSPowerShell.NetCore Cmdlet New-CWEEventBus 3.3.563.1 AWSPowerShell.NetCore Cmdlet New-CWEPartnerEventSource 3.3.563.1 AWSPowerShell.NetCore Cmdlet Remove-CWEEventBus 3.3.563.1 AWSPowerShell.NetCore Cmdlet Remove-CWEPartnerEventSource 3.3.563.1 AWSPowerShell.NetCore Cmdlet Remove-CWEPermission 3.3.563.1 AWSPowerShell.NetCore Cmdlet Remove-CWEResourceTag 3.3.563.1 AWSPowerShell.NetCore Cmdlet Remove-CWERule 3.3.563.1 AWSPowerShell.NetCore Cmdlet Remove-CWETarget 3.3.563.1 AWSPowerShell.NetCore Cmdlet Test-CWEEventPattern 3.3.563.1 AWSPowerShell.NetCore Cmdlet Write-CWEEvent 3.3.563.1 AWSPowerShell.NetCore Cmdlet Write-CWEPartnerEvent 3.3.563.1 AWSPowerShell.NetCore Cmdlet Write-CWEPermission 3.3.563.1 AWSPowerShell.NetCore Cmdlet Write-CWERule 3.3.563.1 AWSPowerShell.NetCore Cmdlet Write-CWETarget 3.3.563.1 AWSPowerShell.NetCore

コマンドレットの名前付けとエイリアス

各サービスの AWS Tools for PowerShell のコマンドレットは、そのサービスの AWS SDK で提供されているメソッドに基づいています。ただし、PowerShell の必須の命名規則のため、コマンドレットの名前は、それが基づく API コールやメソッドの名前とは異なる場合があります。たとえば、Get-EC2Instance コマンドレットは Amazon EC2 DescribeInstances メソッドに基づいています。

コマンドレット名とメソッド名が同じ場合でも、実際に実行される機能は異なることがあります。たとえば、Amazon S3 GetObject メソッドは Amazon S3 オブジェクトを取得します。一方、Get-S3Object コマンドレットは、オブジェクト自体ではなく、Amazon S3 オブジェクトに関する情報を返します。

PS > Get-S3Object -BucketName text-content -Key aws-tech-docs ETag : "df000002a0fe0000f3c000004EXAMPLE" BucketName : aws-tech-docs Key : javascript/frameset.js LastModified : 6/13/2011 1:24:18 PM Owner : Amazon.S3.Model.Owner Size : 512 StorageClass : STANDARD

AWS Tools for PowerShell を使用して S3 オブジェクトを取得するには、Read-S3Object コマンドレットを実行します。

PS > Read-S3Object -BucketName text-content -Key text-object.txt -file c:\tmp\text-object-download.text Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 11/5/2012 7:29 PM 20622 text-object-download.text
注記

AWS コマンドレットのコマンドレットヘルプには、コマンドレットが基づく AWS SDK API の名前が記載されています。

標準の PowerShell 動詞とその意味の詳細については、「Approved Verbs for PowerShell Commands」を参照してください。

Remove 動詞を使用するすべての AWS コマンドレット (および -Terminate パラメータの追加時の Stop-EC2Instance コマンドレット) では、処理を続行する前に確認プロンプトが表示されます。確認を省略するには、コマンドに -Force パラメータを追加します。

重要

AWS コマンドレットでは、-WhatIf スイッチはサポートされていません。

エイリアス

AWS Tools for PowerShell のセットアップでは、多くの AWS コマンドレットのエイリアスが格納されたエイリアスファイルがインストールされます。これらのエイリアスは、コマンドレット名よりも直感的で理解しやすい場合があります。たとえば、一部のエイリアスでは、サービス名と AWS SDK メソッド名によって PowerShell の動詞と名詞が置き換えられます。例として EC2-DescribeInstances エイリアスがあります。

また、標準の PowerShell 命名規則には従わないものの、実際のオペレーションよりもわかりやすい動詞を使用するエイリアスもあります。たとえば、エイリアスファイルでは、エイリアス Get-S3Content がコマンドレット Read-S3Object に対応付けられています。

PS > Set-Alias -Name Get-S3Content -Value Read-S3Object

エイリアスファイルは、AWS Tools for PowerShell インストールディレクトリにあります。使用環境にエイリアスをロードするには、ドットソース形式でファイルを読み込みます。以下は、Windows ベースの例です。

PS > . "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowershell\AWSAliases.ps1"

Linux または macOS シェルの場合、次のようになります。

. ~/.local/share/powershell/Modules/AWSPowerShell.NetCore/3.3.563.1/AWSAliases.ps1

すべての AWS Tools for PowerShell エイリアスを表示するには、次のコマンドを実行します。このコマンドは、PowerShell Where-Object コマンドレットの ? エイリアスと Source プロパティを使用して、AWSPowerShell.NetCore モジュールからのエイリアスのみをフィルタリングします。

PS > Get-Alias | ? Source -like "AWSPowerShell.NetCore" CommandType Name Version Source ----------- ---- ------- ------ Alias Add-ASInstances 3.3.343.0 AWSPowerShell Alias Add-CTTag 3.3.343.0 AWSPowerShell Alias Add-DPTags 3.3.343.0 AWSPowerShell Alias Add-DSIpRoutes 3.3.343.0 AWSPowerShell Alias Add-ELBTags 3.3.343.0 AWSPowerShell Alias Add-EMRTag 3.3.343.0 AWSPowerShell Alias Add-ESTag 3.3.343.0 AWSPowerShell Alias Add-MLTag 3.3.343.0 AWSPowerShell Alias Clear-AWSCredentials 3.3.343.0 AWSPowerShell Alias Clear-AWSDefaults 3.3.343.0 AWSPowerShell Alias Dismount-ASInstances 3.3.343.0 AWSPowerShell Alias Edit-EC2Hosts 3.3.343.0 AWSPowerShell Alias Edit-RSClusterIamRoles 3.3.343.0 AWSPowerShell Alias Enable-ORGAllFeatures 3.3.343.0 AWSPowerShell Alias Find-CTEvents 3.3.343.0 AWSPowerShell Alias Get-ASACases 3.3.343.0 AWSPowerShell Alias Get-ASAccountLimits 3.3.343.0 AWSPowerShell Alias Get-ASACommunications 3.3.343.0 AWSPowerShell Alias Get-ASAServices 3.3.343.0 AWSPowerShell Alias Get-ASASeverityLevels 3.3.343.0 AWSPowerShell Alias Get-ASATrustedAdvisorCheckRefreshStatuses 3.3.343.0 AWSPowerShell Alias Get-ASATrustedAdvisorChecks 3.3.343.0 AWSPowerShell Alias Get-ASATrustedAdvisorCheckSummaries 3.3.343.0 AWSPowerShell Alias Get-ASLifecycleHooks 3.3.343.0 AWSPowerShell Alias Get-ASLifecycleHookTypes 3.3.343.0 AWSPowerShell Alias Get-AWSCredentials 3.3.343.0 AWSPowerShell Alias Get-CDApplications 3.3.343.0 AWSPowerShell Alias Get-CDDeployments 3.3.343.0 AWSPowerShell Alias Get-CFCloudFrontOriginAccessIdentities 3.3.343.0 AWSPowerShell Alias Get-CFDistributions 3.3.343.0 AWSPowerShell Alias Get-CFGConfigRules 3.3.343.0 AWSPowerShell Alias Get-CFGConfigurationRecorders 3.3.343.0 AWSPowerShell Alias Get-CFGDeliveryChannels 3.3.343.0 AWSPowerShell Alias Get-CFInvalidations 3.3.343.0 AWSPowerShell Alias Get-CFNAccountLimits 3.3.343.0 AWSPowerShell Alias Get-CFNStackEvents 3.3.343.0 AWSPowerShell ...

このファイルに独自のエイリアスを追加するには、必要に応じて PowerShell の $MaximumAliasCount ユーザー設定変数の値を 5500 より大きい値に引き上げます。デフォルト値は 4096 であり、これを最大 32768 まで引き上げることができます。これを行うには、次のコマンドを実行します。

PS > $MaximumAliasCount = 32768

変更が正常に行われたことを確認するには、変数名を入力して現在の値を表示します。

PS > $MaximumAliasCount 32768