

第 5 版 (V5) AWS Tools for PowerShell 已發行！

如需有關中斷變更和遷移應用程式的資訊，請參閱[遷移主題](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

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

# 使用 Tools for PowerShell V5 的 Amazon FSx 範例
<a name="powershell_fsx_code_examples"></a>

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

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

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

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

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

### `Add-FSXResourceTag`
<a name="fsx_TagResource_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會將標籤新增至給定的資源。**  

```
Add-FSXResourceTag -ResourceARN "arn:aws:fsx:eu-west-1:123456789012:file-system/fs-01cd23bc4bdf5678a" -Tag @{Key="Users";Value="Test"}
```
**輸出：**  

```
arn:aws:fsx:eu-west-1:123456789012:file-system/fs-01cd23bc4bdf5678a
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [TagResource](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-FSXBackup`
<a name="fsx_DescribeBackups_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會擷取自昨天以來，為給定檔案系統 ID 建立的備份。**  

```
Get-FSXBackup -Filter @{Name="file-system-id";Values=$fsx.FileSystemId} | Where-Object CreationTime -gt (Get-Date).AddDays(-1)
```
**輸出：**  

```
BackupId        : backup-01dac234e56782bcc
CreationTime    : 6/14/2019 3:35:14 AM
FailureDetails  :
FileSystem      : Amazon.FSx.Model.FileSystem
KmsKeyId        : arn:aws:kms:eu-west-1:123456789012:key/f1af23c4-1b23-1bde-a1f1-e1234c5af123
Lifecycle       : AVAILABLE
ProgressPercent : 100
ResourceARN     : arn:aws:fsx:eu-west-1:123456789012:backup/backup-01dac234e56782bcc
Tags            : {}
Type            : AUTOMATIC
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeBackups](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-FSXFileSystem`
<a name="fsx_DescribeFileSystems_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會傳回給定 filesystemId 的描述。**  

```
Get-FSXFileSystem -FileSystemId fs-01cd23bc4bdf5678a
```
**輸出：**  

```
CreationTime         : 1/17/2019 9:55:30 AM
DNSName              : fs-01cd23bc4bdf5678a.ktmsad.local
FailureDetails       :
FileSystemId         : fs-01cd23bc4bdf5678a
FileSystemType       : WINDOWS
KmsKeyId             : arn:aws:kms:eu-west-1:123456789012:key/f1af23c4-5b67-8bde-a9f0-e1234c5af678
Lifecycle            : AVAILABLE
LustreConfiguration  :
NetworkInterfaceIds  : {eni-07d1dda1322b7e209}
OwnerId              : 123456789012
ResourceARN          : arn:aws:fsx:eu-west-1:123456789012:file-system/fs-01cd23bc4bdf5678a
StorageCapacity      : 300
SubnetIds            : {subnet-7d123456}
Tags                 : {FSx-Service}
VpcId                : vpc-41cf2b3f
WindowsConfiguration : Amazon.FSx.Model.WindowsFileSystemConfiguration
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeFileSystems](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-FSXResourceTagList`
<a name="fsx_ListTagsForResource_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會列出所提供資源 arn 的標籤。**  

```
Get-FSXResourceTagList -ResourceARN $fsx.ResourceARN
```
**輸出：**  

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

### `New-FSXBackup`
<a name="fsx_CreateBackup_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會建立給定檔案系統的備份。**  

```
New-FSXBackup -FileSystemId fs-0b1fac2345623456ba
```
**輸出：**  

```
BackupId        : backup-0b1fac2345623456ba
CreationTime    : 6/14/2019 5:37:17 PM
FailureDetails  :
FileSystem      : Amazon.FSx.Model.FileSystem
KmsKeyId        : arn:aws:kms:eu-west-1:123456789012:key/f1af23c4-1b23-1bde-a1f3-e1234c5af678
Lifecycle       : CREATING
ProgressPercent : 0
ResourceARN     : arn:aws:fsx:eu-west-1:123456789012:backup/backup-0b1fac2345623456ba
Tags            : {}
Type            : USER_INITIATED
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateBackup](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-FSXFileSystem`
<a name="fsx_CreateFileSystem_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會建立新的 300GB Windows 檔案系統，允許從指定子網路存取，該存取支援每秒高達 8 MB 的輸送量。新的檔案系統會自動加入指定的 Microsoft Active Directory。**  

```
New-FSXFileSystem -FileSystemType WINDOWS -StorageCapacity 300 -SubnetId subnet-1a2b3c4d5e6f -WindowsConfiguration @{ThroughputCapacity=8;ActiveDirectoryId='d-1a2b3c4d'}
```
**輸出：**  

```
CreationTime         : 12/10/2018 6:06:59 PM
DNSName              : fs-abcdef01234567890.example.com
FailureDetails       :
FileSystemId         : fs-abcdef01234567890
FileSystemType       : WINDOWS
KmsKeyId             : arn:aws:kms:us-west-2:123456789012:key/a1234567-252c-45e9-afaa-123456789abc
Lifecycle            : CREATING
LustreConfiguration  :
NetworkInterfaceIds  : {}
OwnerId              : 123456789012
ResourceARN          : arn:aws:fsx:us-west-2:123456789012:file-system/fs-abcdef01234567890
StorageCapacity      : 300
SubnetIds            : {subnet-1a2b3c4d5e6f}
Tags                 : {}
VpcId                : vpc-1a2b3c4d5e6f
WindowsConfiguration : Amazon.FSx.Model.WindowsFileSystemConfiguration
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateFileSystem](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-FSXFileSystemFromBackup`
<a name="fsx_CreateFileSystemFromBackup_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會從現有的 Amazon FSx for Windows File Server 備份，建立新的 Amazon FSx 檔案系統。**  

```
New-FSXFileSystemFromBackup -BackupId $backupID -Tag @{Key="tag:Name";Value="from-manual-backup"} -SubnetId $SubnetID -SecurityGroupId $SG_ID -WindowsConfiguration @{ThroughputCapacity=8;ActiveDirectoryId=$DirectoryID}
```
**輸出：**  

```
CreationTime         : 8/8/2019 12:59:58 PM
DNSName              : fs-012ff34e56789120.ktmsad.local
FailureDetails       :
FileSystemId         : fs-012ff34e56789120
FileSystemType       : WINDOWS
KmsKeyId             : arn:aws:kms:eu-west-1:123456789012:key/f1af23c4-5b67-1bde-a2f3-e4567c8a9321
Lifecycle            : CREATING
LustreConfiguration  :
NetworkInterfaceIds  : {}
OwnerId              : 933303704102
ResourceARN          : arn:aws:fsx:eu-west-1:123456789012:file-system/fs-012ff34e56789120
StorageCapacity      : 300
SubnetIds            : {subnet-fa1ae23c}
Tags                 : {tag:Name}
VpcId                : vpc-12cf3b4f
WindowsConfiguration : Amazon.FSx.Model.WindowsFileSystemConfiguration
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateFileSystemFromBackup](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-FSXBackup`
<a name="fsx_DeleteBackup_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會移除給定的 backup-id。**  

```
Remove-FSXBackup -BackupId $backupID
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-FSXBackup (DeleteBackup)" on target "backup-0bbca1e2345678e12".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

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

### `Remove-FSXFileSystem`
<a name="fsx_DeleteFileSystem_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會移除給定的 FSX 檔案系統 ID。**  

```
Remove-FSXFileSystem -FileSystemId fs-012ff34e567890120
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-FSXFileSystem (DeleteFileSystem)" on target "fs-012ff34e567890120".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

FileSystemId         Lifecycle WindowsResponse
------------         --------- ---------------
fs-012ff34e567890120 DELETING  Amazon.FSx.Model.DeleteFileSystemWindowsResponse
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteFileSystem](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-FSXResourceTag`
<a name="fsx_UntagResource_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會移除給定 FSX 檔案系統資源 ARN 的資源標籤。**  

```
Remove-FSXResourceTag -ResourceARN $FSX.ResourceARN -TagKey Users
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-FSXResourceTag (UntagResource)" on target "arn:aws:fsx:eu-west-1:933303704102:file-system/fs-07cd45bc6bdf2674a".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UntagResource](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Update-FSXFileSystem`
<a name="fsx_UpdateFileSystem_powershell_topic"></a>

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

**Tools for PowerShell V5**  
**範例 1：此範例會透過 UpdateFileSystemWindowsConfiguration，更新 FSX 檔案系統自動備份保留天數。**  

```
$UpdateFSXWinConfig = [Amazon.FSx.Model.UpdateFileSystemWindowsConfiguration]::new()
	$UpdateFSXWinConfig.AutomaticBackupRetentionDays = 35
	Update-FSXFileSystem -FileSystemId $FSX.FileSystemId -WindowsConfiguration $UpdateFSXWinConfig
```
**輸出：**  

```
CreationTime         : 1/17/2019 9:55:30 AM
DNSName              : fs-01cd23bc4bdf5678a.ktmsad.local
FailureDetails       :
FileSystemId         : fs-01cd23bc4bdf5678a
FileSystemType       : WINDOWS
KmsKeyId             : arn:aws:kms:eu-west-1:123456789012:key/f1af23c4-1b23-1bde-a1f2-e1234c5af678
Lifecycle            : AVAILABLE
LustreConfiguration  :
NetworkInterfaceIds  : {eni-01cd23bc4bdf5678a}
OwnerId              : 933303704102
ResourceARN          : arn:aws:fsx:eu-west-1:933303704102:file-system/fs-07cd45bc6bdf2674a
StorageCapacity      : 300
SubnetIds            : {subnet-1d234567}
Tags                 : {FSx-Service}
VpcId                : vpc-23cf4b5f
WindowsConfiguration : Amazon.FSx.Model.WindowsFileSystemConfiguration
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateFileSystem](https://docs.aws.amazon.com/powershell/v5/reference)。