

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# Directory Service 使用 Tools for PowerShell V5 的範例
<a name="powershell_5_directory-service_code_examples"></a>

下列程式碼範例示範如何使用 AWS Tools for PowerShell V5 搭配 來執行動作和實作常見案例 Directory Service。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

**Topics**
+ [動作](#actions)

## 動作
<a name="actions"></a>

### `Add-DSIpRoute`
<a name="directory-service_AddIpRoutes_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Add-DSIpRoute`。

**Tools for PowerShell V5**  
**範例 1：此命令會移除指派至指定 Directory-id 的資源標籤**  

```
Add-DSIpRoute -DirectoryId d-123456ijkl -IpRoute @{CidrIp ="203.0.113.5/32"} -UpdateSecurityGroupForDirectoryController $true
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AddIpRoutes](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Add-DSResourceTag`
<a name="directory-service_AddTagsToResource_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Add-DSResourceTag`。

**Tools for PowerShell V5**  
**範例 1：此命令會將資源標籤新增至指定的 Directory-id**  

```
Add-DSResourceTag -ResourceId d-123456ijkl -Tag @{Key="myTag"; Value="mytgValue"}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AddTagsToResource](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Approve-DSTrust`
<a name="directory-service_VerifyTrust_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Approve-DSTrust`。

**Tools for PowerShell V5**  
**範例 1：此範例會呼叫指定 Trustid 的 AWS Directory Service VerifyTrust API 操作。**  

```
Approve-DSTrust -TrustId t-9067157123
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [VerifyTrust](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Confirm-DSSharedDirectory`
<a name="directory-service_AcceptSharedDirectory_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Confirm-DSSharedDirectory`。

**Tools for PowerShell V5**  
**範例 1：此範例接受從目錄擁有者傳送的目錄共用請求 AWS 帳戶。**  

```
Confirm-DSSharedDirectory -SharedDirectoryId d-9067012345
```
**輸出：**  

```
CreatedDateTime     : 12/30/2019 4:20:27 AM
LastUpdatedDateTime : 12/30/2019 4:21:40 AM
OwnerAccountId      : 123456781234
OwnerDirectoryId    : d-123456ijkl
SharedAccountId     : 123456784321
SharedDirectoryId   : d-9067012345
ShareMethod         :
ShareNotes          : This is test sharing
ShareStatus         : Sharing
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [AcceptSharedDirectory](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Connect-DSDirectory`
<a name="directory-service_ConnectDirectory_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Connect-DSDirectory`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立 AD Connector，以連接到內部部署目錄。**  

```
Connect-DSDirectory -Name contoso.com -ConnectSettings_CustomerUserName Administrator -Password $Password -ConnectSettings_CustomerDnsIp 172.31.36.96 -ShortName CONTOSO -Size Small -ConnectSettings_VpcId vpc-123459da -ConnectSettings_SubnetId subnet-1234ccaa, subnet-5678ffbb
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ConnectDirectory](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Deny-DSSharedDirectory`
<a name="directory-service_RejectSharedDirectory_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Deny-DSSharedDirectory`。

**Tools for PowerShell V5**  
**範例 1：此範例拒絕從目錄擁有者傳送的目錄共用請求。**  

```
Deny-DSSharedDirectory -SharedDirectoryId d-9067012345
```
**輸出：**  

```
d-9067012345
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RejectSharedDirectory](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Disable-DSDirectoryShare`
<a name="directory-service_UnshareDirectory_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Disable-DSDirectoryShare`。

**Tools for PowerShell V5**  
**範例 1：此範例會停止目錄擁有者與取用者帳戶之間的目錄共用。**  

```
Disable-DSDirectoryShare -DirectoryId d-123456ijkl -UnshareTarget_Id 123456784321 -UnshareTarget_Type ACCOUNT
```
**輸出：**  

```
d-9067012345
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UnshareDirectory](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Disable-DSLDAPS`
<a name="directory-service_DisableLDAPS_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Disable-DSLDAPS`。

**Tools for PowerShell V5**  
**範例 1：此範例會停用指定目錄的 LDAP 安全呼叫。**  

```
Disable-DSLDAPS -DirectoryId d-123456ijkl -Type Client
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DisableLDAPS](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Disable-DSRadius`
<a name="directory-service_DisableRadius_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Disable-DSRadius`。

**Tools for PowerShell V5**  
**範例 1：此範例會停用針對 AD Connector 或 Microsoft AD 目錄設定的 RADIUS 伺服器。**  

```
Disable-DSRadius -DirectoryId d-123456ijkl
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DisableRadius](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Disable-DSSso`
<a name="directory-service_DisableSso_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Disable-DSSso`。

**Tools for PowerShell V5**  
**範例 1：此範例會停用目錄的單一登入。**  

```
Disable-DSSso -DirectoryId d-123456ijkl
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DisableSso](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Enable-DSDirectoryShare`
<a name="directory-service_ShareDirectory_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Enable-DSDirectoryShare`。

**Tools for PowerShell V5**  
**範例 1：此範例使用交握方法與另一個 AWS 帳戶共用您 AWS 帳戶中的指定目錄。 **  

```
Enable-DSDirectoryShare -DirectoryId d-123456ijkl -ShareTarget_Id 123456784321 -ShareMethod HANDSHAKE -ShareTarget_Type ACCOUNT
```
**輸出：**  

```
d-9067012345
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ShareDirectory](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Enable-DSLDAPS`
<a name="directory-service_EnableLDAPS_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Enable-DSLDAPS`。

**Tools for PowerShell V5**  
**範例 1：此範例啟用特定目錄的切換開關，以永遠使用 LDAP 安全呼叫。**  

```
Enable-DSLDAPS -DirectoryId d-123456ijkl -Type Client
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**的 [EnableLDAPS](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Enable-DSRadius`
<a name="directory-service_EnableRadius_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Enable-DSRadius`。

**Tools for PowerShell V5**  
**範例 1：此範例利用 AD Connector 或 Microsoft AD 目錄的 RADIUS 伺服器組態，啟用多重要素驗證 (MFA)。**  

```
Enable-DSRadius -DirectoryId d-123456ijkl 
-RadiusSettings_AuthenticationProtocol PAP 
-RadiusSettings_DisplayLabel Radius 
-RadiusSettings_RadiusPort 1812 
-RadiusSettings_RadiusRetry 4 
-RadiusSettings_RadiusServer 10.4.185.113 
-RadiusSettings_RadiusTimeout 50 
-RadiusSettings_SharedSecret wJalrXUtnFEMI
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [EnableRadius](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Enable-DSSso`
<a name="directory-service_EnableSso_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Enable-DSSso`。

**Tools for PowerShell V5**  
**範例 1：此範例會啟用目錄的單一登入。**  

```
Enable-DSSso -DirectoryId d-123456ijkl
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [EnableSso](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSCertificate`
<a name="directory-service_DescribeCertificate_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSCertificate`。

**Tools for PowerShell V5**  
**範例 1：此範例顯示為安全 LDAP 連線註冊的憑證相關資訊。**  

```
Get-DSCertificate -DirectoryId d-123456ijkl -CertificateId c-906731e34f
```
**輸出：**  

```
CertificateId      : c-906731e34f
CommonName         : contoso-EC2AMAZ-CTGG2NM-CA
ExpiryDateTime     : 4/15/2025 6:34:15 PM
RegisteredDateTime : 4/15/2020 6:38:56 PM
State              : Registered
StateReason        : Certificate registered successfully.
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeCertificate](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSCertificateList`
<a name="directory-service_ListCertificates_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSCertificateList`。

**Tools for PowerShell V5**  
範例 1：此範例針對指定的目錄，列出已註冊為安全 LDAP 連線的所有憑證。****  

```
Get-DSCertificateList -DirectoryId d-123456ijkl
```
**輸出：**  

```
CertificateId CommonName                 ExpiryDateTime       State
------------- ----------                 --------------       -----
c-906731e34f  contoso-EC2AMAZ-CTGG2NM-CA 4/15/2025 6:34:15 PM Registered
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListCertificates](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSConditionalForwarder`
<a name="directory-service_DescribeConditionalForwarders_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSConditionalForwarder`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得給定 Directory-id 的所有設定的條件式轉寄站。**  

```
Get-DSConditionalForwarder -DirectoryId d-123456ijkl
```
**輸出：**  

```
DnsIpAddrs      RemoteDomainName ReplicationScope
----------      ---------------- ----------------
{172.31.77.239} contoso.com      Domain
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeConditionalForwarders](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSDirectory`
<a name="directory-service_DescribeDirectories_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSDirectory`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得屬於此帳戶的目錄的相關資訊。**  

```
Get-DSDirectory | Select-Object DirectoryId, Name, DnsIpAddrs, Type
```
**輸出：**  

```
DirectoryId  Name           DnsIpAddrs                     Type
-----------  ----           ----------                     ----
d-123456abcd abcd.example.com {172.31.74.189, 172.31.13.145} SimpleAD
d-123456efgh wifi.example.com {172.31.16.108, 172.31.10.56}  ADConnector
d-123456ijkl lan2.example.com {172.31.10.56, 172.31.16.108}  MicrosoftAD
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeDirectories](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSDirectoryLimit`
<a name="directory-service_GetDirectoryLimits_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSDirectoryLimit`。

**Tools for PowerShell V5**  
**範例 1：此範例會顯示 us-east-1 區域的目錄限制資訊。**  

```
Get-DSDirectoryLimit -Region us-east-1
```
**輸出：**  

```
CloudOnlyDirectoriesCurrentCount : 1
CloudOnlyDirectoriesLimit        : 10
CloudOnlyDirectoriesLimitReached : False
CloudOnlyMicrosoftADCurrentCount : 1
CloudOnlyMicrosoftADLimit        : 20
CloudOnlyMicrosoftADLimitReached : False
ConnectedDirectoriesCurrentCount : 1
ConnectedDirectoriesLimit        : 10
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetDirectoryLimits](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSDomainControllerList`
<a name="directory-service_DescribeDomainControllers_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSDomainControllerList`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得針對提及的 directory-id 啟動的網域控制站詳細清單**  

```
Get-DSDomainControllerList -DirectoryId d-123456ijkl
```
**輸出：**  

```
AvailabilityZone          : us-east-1b
DirectoryId               : d-123456ijkl
DnsIpAddr                 : 172.31.16.108
DomainControllerId        : dc-1234567aa6
LaunchTime                : 4/4/2019 4:53:43 AM
Status                    : Active
StatusLastUpdatedDateTime : 4/24/2019 1:37:54 PM
StatusReason              :
SubnetId                  : subnet-1234kkaa
VpcId                     : vpc-123459d

AvailabilityZone          : us-east-1d
DirectoryId               : d-123456ijkl
DnsIpAddr                 : 172.31.10.56
DomainControllerId        : dc-1234567aa7
LaunchTime                : 4/4/2019 4:53:43 AM
Status                    : Active
StatusLastUpdatedDateTime : 4/4/2019 5:14:31 AM
StatusReason              :
SubnetId                  : subnet-5678ffbb
VpcId                     : vpc-123459d
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeDomainControllers](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSEventTopic`
<a name="directory-service_DescribeEventTopics_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSEventTopic`。

**Tools for PowerShell V5**  
**範例 1：此命令顯示目錄狀態變更時所設定 SNS 主題的通知資訊。**  

```
Get-DSEventTopic -DirectoryId d-123456ijkl
```
**輸出：**  

```
CreatedDateTime : 12/13/2019 11:15:32 AM
DirectoryId     : d-123456ijkl
Status          : Registered
TopicArn        : arn:aws:sns:us-east-1:123456781234:snstopicname
TopicName       : snstopicname
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeEventTopics](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSIpRouteList`
<a name="directory-service_ListIpRoutes_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSIpRouteList`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得在目錄 IP 路由中設定的公有 IP 位址區塊**  

```
Get-DSIpRouteList -DirectoryId d-123456ijkl
```
**輸出：**  

```
AddedDateTime       : 12/13/2019 12:27:22 PM
CidrIp              : 203.0.113.5/32
Description         : Public IP of On-Prem DNS Server
DirectoryId         : d-123456ijkl
IpRouteStatusMsg    : Added
IpRouteStatusReason :
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListIpRoutes](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSLDAPSSetting`
<a name="directory-service_DescribeLDAPSSettings_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSLDAPSSetting`。

**Tools for PowerShell V5**  
**範例 1：此範例描述指定目錄的 LDAP 安全狀態。**  

```
Get-DSLDAPSSetting -DirectoryId d-123456ijkl
```
**輸出：**  

```
LastUpdatedDateTime  LDAPSStatus LDAPSStatusReason
-------------------  ----------- -----------------
4/15/2020 6:51:03 PM Enabled     LDAPS is enabled successfully.
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeLDAPSSettings](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSLogSubscriptionList`
<a name="directory-service_ListLogSubscriptions_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSLogSubscriptionList`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得指定 directory-id 的日誌訂閱資訊**  

```
Get-DSLogSubscriptionList -DirectoryId d-123456ijkl
```
**輸出：**  

```
DirectoryId  LogGroupName                                        SubscriptionCreatedDateTime
-----------  ------------                                        ---------------------------
d-123456ijkl /aws/directoryservice/d-123456ijkl-lan2.example.com 12/14/2019 9:05:23 AM
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListLogSubscriptions](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSResourceTag`
<a name="directory-service_ListTagsForResource_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSResourceTag`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得指定目錄的所有標籤。**  

```
Get-DSResourceTag -ResourceId d-123456ijkl
```
**輸出：**  

```
Key   Value
---   -----
myTag myTagValue
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListTagsForResource](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSSchemaExtension`
<a name="directory-service_ListSchemaExtensions_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSSchemaExtension`。

**Tools for PowerShell V5**  
**範例 1：此範例列出套用到 Microsoft AD 目錄的所有結構描述延伸。**  

```
Get-DSSchemaExtension -DirectoryId d-123456ijkl
```
**輸出：**  

```
Description                 : ManagedADSchemaExtension
DirectoryId                 : d-123456ijkl
EndDateTime                 : 4/12/2020 10:30:49 AM
SchemaExtensionId           : e-9067306643
SchemaExtensionStatus       : Completed
SchemaExtensionStatusReason : Schema updates are complete.
StartDateTime               : 4/12/2020 10:28:42 AM
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListSchemaExtensions](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSSharedDirectory`
<a name="directory-service_DescribeSharedDirectories_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSSharedDirectory`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得您 AWS 帳戶的共用目錄**  

```
Get-DSSharedDirectory -OwnerDirectoryId d-123456ijkl -SharedDirectoryId d-9067012345
```
**輸出：**  

```
CreatedDateTime     : 12/30/2019 4:34:37 AM
LastUpdatedDateTime : 12/30/2019 4:35:22 AM
OwnerAccountId      : 123456781234
OwnerDirectoryId    : d-123456ijkl
SharedAccountId     : 123456784321
SharedDirectoryId   : d-9067012345
ShareMethod         : HANDSHAKE
ShareNotes          : This is a test Sharing
ShareStatus         : Shared
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeSharedDirectories](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSSnapshot`
<a name="directory-service_DescribeSnapshots_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSSnapshot`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得屬於此帳戶之指定目錄快照的相關資訊。**  

```
Get-DSSnapshot -DirectoryId d-123456ijkl
```
**輸出：**  

```
DirectoryId : d-123456ijkl
Name        :
SnapshotId  : s-9064bd1234
StartTime   : 12/13/2019 6:33:01 PM
Status      : Completed
Type        : Auto

DirectoryId : d-123456ijkl
Name        :
SnapshotId  : s-9064bb4321
StartTime   : 12/9/2019 9:48:11 PM
Status      : Completed
Type        : Auto
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeSnapshots](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSSnapshotLimit`
<a name="directory-service_GetSnapshotLimits_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSSnapshotLimit`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得指定目錄的手動快照限制。**  

```
Get-DSSnapshotLimit -DirectoryId d-123456ijkl
```
**輸出：**  

```
ManualSnapshotsCurrentCount ManualSnapshotsLimit ManualSnapshotsLimitReached
--------------------------- -------------------- ---------------------------
0                           5                    False
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetSnapshotLimits](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-DSTrust`
<a name="directory-service_DescribeTrusts_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Get-DSTrust`。

**Tools for PowerShell V5**  
**範例 1：此命令會取得為指定之 directory-id 建立的信任關係資訊。**  

```
Get-DSTrust -DirectoryId d-123456abcd
```
**輸出：**  

```
CreatedDateTime          : 7/5/2019 4:55:42 AM
DirectoryId              : d-123456abcd
LastUpdatedDateTime      : 7/5/2019 4:56:04 AM
RemoteDomainName         : contoso.com
SelectiveAuth            : Disabled
StateLastUpdatedDateTime : 7/5/2019 4:56:04 AM
TrustDirection           : One-Way: Incoming
TrustId                  : t-9067157123
TrustState               : Created
TrustStateReason         :
TrustType                : Forest
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeTrusts](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-DSAlias`
<a name="directory-service_CreateAlias_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `New-DSAlias`。

**Tools for PowerShell V5**  
**範例 1：此命令會建立目錄的別名，並將別名指派給指定的 directory-id。**  

```
New-DSAlias -DirectoryId d-123456ijkl -Alias MyOrgName
```
**輸出：**  

```
Alias     DirectoryId
-----     -----------
myorgname d-123456ijkl
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateAlias](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-DSComputer`
<a name="directory-service_CreateComputer_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `New-DSComputer`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立新的 Active Directory 電腦物件。**  

```
New-DSComputer -DirectoryId d-123456ijkl -ComputerName ADMemberServer -Password $Password
```
**輸出：**  

```
ComputerAttributes                  ComputerId                                    ComputerName
------------------                  ----------                                    ------------
{WindowsSamName, DistinguishedName} S-1-5-21-1191241402-978882507-2717148213-1662 ADMemberServer
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateComputer](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-DSConditionalForwarder`
<a name="directory-service_CreateConditionalForwarder_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `New-DSConditionalForwarder`。

**Tools for PowerShell V5**  
**範例 1：此範例會在指定的 AWS Directory-id 中建立條件式轉送器。 **  

```
New-DSConditionalForwarder -DirectoryId d-123456ijkl -DnsIpAddr 172.31.36.96,172.31.10.56 -RemoteDomainName contoso.com
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateConditionalForwarder](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-DSDirectory`
<a name="directory-service_CreateDirectory_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `New-DSDirectory`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立新的 Simple AD 目錄。**  

```
New-DSDirectory -Name corp.example.com -Password $Password -Size Small -VpcSettings_VpcId vpc-123459d -VpcSettings_SubnetIds subnet-1234kkaa,subnet-5678ffbb
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateDirectory](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-DSLogSubscription`
<a name="directory-service_CreateLogSubscription_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `New-DSLogSubscription`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立訂閱，將即時 Directory Service 網域控制器安全日誌轉送到您 AWS 帳戶中指定的 Amazon CloudWatch 日誌群組。**  

```
New-DSLogSubscription -DirectoryId d-123456ijkl -LogGroupName /aws/directoryservice/d-123456ijkl-lan2.example.com
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateLogSubscription](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-DSMicrosoftAD`
<a name="directory-service_CreateMicrosoftAD_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `New-DSMicrosoftAD`。

**Tools for PowerShell V5**  
**範例 1：此範例會在 中建立新的 Microsoft AD Directory AWS 雲端。**  

```
New-DSMicrosoftAD -Name corp.example.com -Password $Password -edition Standard -VpcSettings_VpcId vpc-123459d -VpcSettings_SubnetIds subnet-1234kkaa,subnet-5678ffbb
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateMicrosoftAD](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-DSSnapshot`
<a name="directory-service_CreateSnapshot_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `New-DSSnapshot`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立目錄快照**  

```
New-DSSnapshot -DirectoryId d-123456ijkl
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-DSTrust`
<a name="directory-service_CreateTrust_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `New-DSTrust`。

**Tools for PowerShell V5**  
**範例 1：此範例會在 AWS Managed Microsoft AD 目錄與現有的內部部署 Microsoft Active Directory 之間建立雙向全森林信任。**  

```
New-DSTrust -DirectoryId d-123456ijkl -RemoteDomainName contoso.com -TrustDirection Two-Way -TrustType Forest -TrustPassword $Password -ConditionalForwarderIpAddr 172.31.36.96
```
**輸出：**  

```
t-9067157123
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateTrust](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Register-DSCertificate`
<a name="directory-service_RegisterCertificate_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Register-DSCertificate`。

**Tools for PowerShell V5**  
**範例 1：此範例為註冊安全 LDAP 連線的憑證。**  

```
$Certificate = Get-Content contoso.cer -Raw
Register-DSCertificate -DirectoryId d-123456ijkl -CertificateData $Certificate
```
**輸出：**  

```
c-906731e350
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RegisterCertificate](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Register-DSEventTopic`
<a name="directory-service_RegisterEventTopic_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Register-DSEventTopic`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立用作發布者的目錄，與 SNS 主題的關聯。**  

```
Register-DSEventTopic -DirectoryId d-123456ijkl -TopicName snstopicname
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RegisterEventTopic](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-DSConditionalForwarder`
<a name="directory-service_DeleteConditionalForwarder_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Remove-DSConditionalForwarder`。

**Tools for PowerShell V5**  
**範例 1：此範例會移除已為您的 AWS 分類設定的條件式轉送器。**  

```
Remove-DSConditionalForwarder -DirectoryId d-123456ijkl -RemoteDomainName contoso.com
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteConditionalForwarder](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-DSDirectory`
<a name="directory-service_DeleteDirectory_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Remove-DSDirectory`。

**Tools for PowerShell V5**  
**範例 1：此範例會刪除 AWS Directory 服務目錄 (Simple AD/Microsoft AD/AD Connector)**  

```
Remove-DSDirectory -DirectoryId d-123456ijkl
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteDirectory](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-DSIpRoute`
<a name="directory-service_RemoveIpRoutes_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Remove-DSIpRoute`。

**Tools for PowerShell V5**  
**範例 1：此命令會從 Directory-id 的已設定 IP 路由中，移除指定的 IP。**  

```
Remove-DSIpRoute -DirectoryId d-123456ijkl -CidrIp 203.0.113.5/32
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RemoveIpRoutes](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-DSLogSubscription`
<a name="directory-service_DeleteLogSubscription_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Remove-DSLogSubscription`。

**Tools for PowerShell V5**  
**範例 1：此命令會移除指定之 Directory-id 的日誌訂閱**  

```
Remove-DSLogSubscription -DirectoryId d-123456ijkl
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteLogSubscription](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-DSResourceTag`
<a name="directory-service_RemoveTagsFromResource_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Remove-DSResourceTag`。

**Tools for PowerShell V5**  
**範例 1：此命令會移除指派至指定 Directory-id 的資源標籤**  

```
Remove-DSResourceTag -ResourceId d-123456ijkl -TagKey myTag
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RemoveTagsFromResource](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-DSSnapshot`
<a name="directory-service_DeleteSnapshot_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Remove-DSSnapshot`。

**Tools for PowerShell V5**  
**範例 1：此範例會移除手動建立的快照。**  

```
Remove-DSSnapshot -SnapshotId s-9068b488kc
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-DSTrust`
<a name="directory-service_DeleteTrust_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Remove-DSTrust`。

**Tools for PowerShell V5**  
**範例 1：此範例會移除 AWS Managed AD Directory 與外部網域之間存在的信任關係。**  

```
Get-DSTrust -DirectoryId d-123456ijkl -Select Trusts.TrustId | Remove-DSTrust
```
**輸出：**  

```
t-9067157123
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteTrust](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Reset-DSUserPassword`
<a name="directory-service_ResetUserPassword_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Reset-DSUserPassword`。

**Tools for PowerShell V5**  
**範例 1：此範例會在 AWS Managed microsoft AD 或 Simple AD Directory 中重設名為 ADUser 的 Active Direcotry 使用者密碼**  

```
Reset-DSUserPassword -UserName ADuser -DirectoryId d-123456ijkl -NewPassword $Password
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ResetUserPassword](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Restore-DSFromSnapshot`
<a name="directory-service_RestoreFromSnapshot_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Restore-DSFromSnapshot`。

**Tools for PowerShell V5**  
**範例 1：此範例使用現有的目錄快照還原目錄。**  

```
Restore-DSFromSnapshot -SnapshotId s-9068b488kc
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RestoreFromSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-DSDomainControllerCount`
<a name="directory-service_UpdateNumberOfDomainControllers_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Set-DSDomainControllerCount`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定之 directory-id 的網域控制站數目設定為 3。**  

```
Set-DSDomainControllerCount -DirectoryId d-123456ijkl -DesiredNumber 3
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateNumberOfDomainControllers](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Start-DSSchemaExtension`
<a name="directory-service_StartSchemaExtension_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Start-DSSchemaExtension`。

**Tools for PowerShell V5**  
**範例 1：此範例會將結構描述延伸，套用至 Microsoft AD 目錄。**  

```
$ldif = Get-Content D:\Users\Username\Downloads\ExtendedSchema.ldf -Raw
Start-DSSchemaExtension -DirectoryId d-123456ijkl -CreateSnapshotBeforeSchemaExtension $true -Description ManagedADSchemaExtension -LdifContent $ldif
```
**輸出：**  

```
e-9067306643
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [StartSchemaExtension](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Stop-DSSchemaExtension`
<a name="directory-service_CancelSchemaExtension_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Stop-DSSchemaExtension`。

**Tools for PowerShell V5**  
**範例 1：此範例會取消 Microsoft AD 目錄的進行中結構描述延伸。**  

```
Stop-DSSchemaExtension -DirectoryId d-123456ijkl -SchemaExtensionId e-9067306643
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CancelSchemaExtension](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Unregister-DSCertificate`
<a name="directory-service_DeregisterCertificate_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Unregister-DSCertificate`。

**Tools for PowerShell V5**  
**範例 1：此範例會將從系統刪除已註冊安全 LDAP 連線的憑證。**  

```
Unregister-DSCertificate -DirectoryId d-123456ijkl -CertificateId c-906731e34f
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeregisterCertificate](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Unregister-DSEventTopic`
<a name="directory-service_DeregisterEventTopic_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Unregister-DSEventTopic`。

**Tools for PowerShell V5**  
**範例 1：此範例會移除用作指定之 SNS 主題發布者的指定目錄。**  

```
Unregister-DSEventTopic -DirectoryId d-123456ijkl -TopicName snstopicname
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeregisterEventTopic](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Update-DSConditionalForwarder`
<a name="directory-service_UpdateConditionalForwarder_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Update-DSConditionalForwarder`。

**Tools for PowerShell V5**  
**範例 1：此範例會更新已為您的 AWS 目錄設定的條件式轉送器。**  

```
Update-DSConditionalForwarder -DirectoryId d-123456ijkl -DnsIpAddr 172.31.36.96,172.31.16.108 -RemoteDomainName contoso.com
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateConditionalForwarder](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Update-DSRadius`
<a name="directory-service_UpdateRadius_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Update-DSRadius`。

**Tools for PowerShell V5**  
**範例 1：此範例會更新 AD Connector 或 Microsoft AD 目錄的 RADIUS 伺服器資訊。**  

```
Update-DSRadius -DirectoryId d-123456ijkl -RadiusSettings_RadiusRetry 3
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateRadius](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Update-DSTrust`
<a name="directory-service_UpdateTrust_powershell_5_topic"></a>

以下程式碼範例顯示如何使用 `Update-DSTrust`。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定 trust-id 的 SelectiveAuth 參數，從「已停用」更新為「已啟用」。**  

```
Update-DSTrust -TrustId t-9067157123 -SelectiveAuth Enabled
```
**輸出：**  

```
RequestId                            TrustId
---------                            -------
138864a7-c9a8-4ad1-a828-eae479e85b45 t-9067157123
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateTrust](https://docs.aws.amazon.com/powershell/v5/reference)。