

AWS Tools for PowerShell V4 已進入維護模式。

我們建議您遷移至 [AWS Tools for PowerShell V5](https://docs.aws.amazon.com/powershell/v5/userguide/)。如需如何遷移的其他詳細資訊和資訊，請參閱我們的[維護模式公告](https://aws.amazon.com/blogs/developer/aws-tools-for-powershell-v4-maintenance-mode-announcement/)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Cmdlet 探索和別名
<a name="pstools-discovery-aliases"></a>

本節說明如何列出 支援的服務 AWS Tools for PowerShell、如何顯示 提供的一組 Cmdlet AWS Tools for PowerShell 以支援這些服務，以及如何尋找替代 Cmdlet 名稱 （也稱為別名） 以存取這些服務。

## Cmdlet 探索
<a name="pstools-cmdlet-discovery"></a>

所有 AWS 服務操作 （或 APIs) 都會記錄在每項服務的 API 參考指南中。舉例來說，請參閱 [IAM API 參考](https://docs.aws.amazon.com/IAM/latest/APIReference/)。在大多數情況下， AWS 服務 API 和 AWS PowerShell Cmdlet one-to-one通訊。若要取得與服務 AWS API 名稱對應的 cmdlet 名稱，請使用 AWS `-ApiOperation` 參數和服務 AWS API 名稱執行 `Get-AWSCmdletName` cmdlet。例如，若要取得以任何可用`DescribeInstances` AWS 服務 API 為基礎的所有可能 cmdlet 名稱，請執行下列命令：

```
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 和服務的名稱，您可以包含 `-Service` 參數以及 cmdlet 名詞字首或服務 AWS 名稱的一部分。例如，適用於 Amazon EC2 的 Cmdlet 名詞字首為 `EC2`。若要取得對應到 Amazon EC2 服務中 `DescribeInstances` API 的 Cmdlet 名稱，請執行以下其中一個命令。他們都會產生相同的輸出：

```
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 ，您可以使用 `-ApiOperation` 參數，以及要比對的模式，以及 `-MatchWithRegex` 參數。例如，若要取得包含 `SecurityGroup` 的所有可用 Cmdlet 名稱，執行以下命令：

```
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` 的所有 Cmdlet 名稱，請執行以下命令

```
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 為基礎的 cmdlet 名稱。例如，若要取得與 Amazon EC2 服務中`authorize-security-group-ingress` AWS CLI 命令呼叫對應的 cmdlet 名稱，請執行下列命令：

```
PS > Get-AWSCmdletName -AwsCliCommand "aws ec2 authorize-security-group-ingress"

CmdletName                    ServiceOperation              ServiceName                  CmdletNounPrefix
----------                    ----------------              -----------                  ----------------
Grant-EC2SecurityGroupIngress AuthorizeSecurityGroupIngress Amazon Elastic Compute Cloud EC2
```

`Get-AWSCmdletName` cmdlet 只需要足夠的 AWS CLI 命令名稱來識別服務和 AWS API。

若要取得 Tools for PowerShell Core 中所有 Cmdlet 的清單，請執行 PowerShell `Get-Command` Cmdlet，如以下範例所示。

```
PS > Get-Command -Module AWSPowerShell.NetCore
```

您可以搭配 `-Module AWSPowerShell` 執行相同的命令，來查看 AWS Tools for Windows PowerShell中的 Cmdlet。

`Get-Command` Cmdlet 產生的 Cmdlet 清單會以字母順序排序。請注意，根據預設，清單會根據 PowerShell 動詞排序，而非 PowerShell 名詞。

若要改為根據服務來排序結果，請執行以下命令：

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

若要篩選由 `Get-Command` Cmdlet 傳回的 Cmdlet，請將輸出輸送到 PowerShell `Select-String` Cmdlet。例如，若要檢視使用 AWS 區域的一組 cmdlet，請執行下列命令：

```
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
```

您亦可篩選 cmdlet 名詞的服務字首，藉此尋找特定服務的 cmdlet。若要查看可用服務字首的清單，請執行 `Get-AWSPowerShellVersion -ListServiceVersionInfo`。以下範例會傳回支援 Amazon CloudWatch Events 服務的 Cmdlet。

```
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
```

## Cmdlet 命名和別名
<a name="pstools-cmdlet-naming-aliases"></a>

 AWS Tools for PowerShell 中每個服務的 cmdlet 是根據服務 AWS SDK 提供的方法。但是，由於 PowerShell 的強制命名慣例，Cmdlet 的名稱可能會和 API 呼叫名稱，或其根據的方法名稱不同。例如，`Get-EC2Instance` cmdlet 是根據 Amazon EC2 `DescribeInstances` 方法。

在某些情況下，cmdlet 名稱可能與方法名稱類似，但實際執行的功能則不同。例如，Amazon S3 `GetObject` 方法會擷取 Amazon S3 物件。然而，`Get-S3Object` cmdlet 會回傳 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
```

若要使用 取得 S3 物件 AWS Tools for PowerShell，請執行 `Read-S3Object` cmdlet：

```
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
```

**注意**  
Cmdlet 的 AWS Cmdlet 說明提供 Cmdlet 所依據的 AWS SDK API 名稱。  
如需標準 PowerShell 動詞及其含意的詳細資訊，請參閱[核准的 PowerShell 命令動詞](https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands)。

當您新增 `-Terminate` 參數時，所有使用動詞的 AWS cmdlet – `Remove` 和 `Stop-EC2Instance` cmdlet – 在繼續之前提示確認。若要略過確認，可在命令裡加入 `-Force` 參數。

**重要**  
AWS cmdlet 不支援`-WhatIf`切換。

### Aliases
<a name="pstools-aliases"></a>

的安裝會 AWS Tools for PowerShell 安裝別名檔案，其中包含許多 AWS cmdlet 的別名。這些別名可能較 cmdlet 名稱更為直觀。例如，服務名稱和 AWS SDK 方法名稱會取代某些別名中的 PowerShell 動詞和名詞。`EC2-DescribeInstances` 別名就是一個範例。

其他別名即使未遵從標準 PowerShell 慣例，但其使用的動詞可能更詳細描述實際操作。例如，別名檔案會將別名 `Get-S3Content` 對應至 cmdlet `Read-S3Object`。

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

別名檔案位於 AWS Tools for PowerShell 安裝目錄中。若要將別名載入到您的環境，請對該檔案使用 *dot-source*命令。以下是 Windows 的範例。

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

針對 Linux 或 macOS shell，它看起來會如下：

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

若要顯示所有 AWS Tools for PowerShell 別名，請執行下列命令。這個命令會使用 PowerShell `Where-Object` Cmdlet 的 `?` 別名，以及 `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` [偏好變數](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-6)值提高為大於 5500 的值。預設值為 4096；最多可以提高到 32768。若要進行這項動作，請執行下列命令。

```
PS > $MaximumAliasCount = 32768
```

若要確認變更成功，可輸入變數名稱以顯示其目前的值。

```
PS > $MaximumAliasCount
32768
```