

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

# 常用案例
<a name="fsrm-common-use-cases"></a>

本主題提供常見 File Server Resource Manager 任務的step-by-step範例。這些範例示範如何使用和實作 FSRM 功能來解決典型的檔案管理挑戰。

**注意**  
此頁面中的所有範例皆假設您已使用檔案系統的 Windows Remote PowerShell 端點定義 ` $FSxWindowsRemotePowerShellEndpoint`變數。您可以在檔案系統的詳細資訊頁面上的 Amazon FSx 主控台中找到此端點，或使用 AWS CLI `describe-file-systems`命令。

## 在資料夾上設定硬性配額
<a name="fsrm-setting-hard-quota"></a>

此範例示範如何建立硬配額，以防止使用者在「部門」資料夾中儲存超過 10 GB。

**若要設定資料夾的配額：**

1. 建立 10 GB 限制的硬性配額：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       New-FSxFSRMQuota -Folder "share\department" -Size 10GB -Description "10 GB hard limit for department folder" 
   }
   ```

1. （選用） 修改配額以新增 85% 用量的閾值通知：

   ```
   $thresholds = [System.Collections.ArrayList]@() 
   $threshold = @{ 
       ThresholdPercentage = 85 
       Action = @( 
           @{ 
               ActionType = "Event" 
               EventType = "Warning" 
               MessageBody = "Department folder has reached 85% of quota limit" 
           } 
       ) 
   } 
   
   $null = $thresholds.Add($threshold) 
   
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ArgumentList ($thresholds) -ScriptBlock { 
       param($thresholds) 
       Set-FSxFSRMQuota -Folder "share\department" -ThresholdConfigurations $Using:thresholds 
   }
   ```

1. 確認已建立配額：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Get-FSxFSRMQuota -Folder "share\department"
   }
   ```

## 使用檔案群組限制特定檔案類型
<a name="fsrm-restricting-file-types"></a>

此範例示範如何使用預設的「`Audio and Video Files`」檔案群組，封鎖使用者將音訊和影片檔案儲存至商業文件資料夾。

**若要使用檔案群組來限制檔案類型：**

1. 建立可封鎖音訊和影片檔案的作用中檔案畫面：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
   New-FSxFSRMFileScreen -Folder "share\business-documents" -IncludeGroup "Audio and Video Files" -Description "Block media files in business documents folder" 
   }
   ```

1. （選用） 更新檔案畫面，以在使用者嘗試儲存封鎖的檔案時新增通知：

   ```
   $notifications = [System.Collections.ArrayList]@()
                       
   $eventNotification = @{
       ActionType = "Event"
       EventType = "Warning"
       MessageBody = "User attempted to save blocked media file"
   }
   $null = $notifications.Add($eventNotification)
   
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ArgumentList $notifications -ScriptBlock {
       param($notifications)
       Set-FSxFSRMFileScreen -Folder "share\business-documents" -NotificationConfigurations $Using:notifications 
   }
   ```

1. 確認已建立檔案畫面：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Get-FSxFSRMFileScreen -Folder "share\business-documents"
   }
   ```

## 識別和分類 PII 資料
<a name="fsrm-identify-classify-pii"></a>

此範例說明如何自動識別包含社會安全號碼的檔案，並將其分類為包含個人身分識別資訊 (PII)。

**若要識別和分類 PII 資料：**

1. 建立 PII 的分類屬性：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       New-FSxFSRMClassificationPropertyDefinition -Name "ContainsPII" -Type OrderedList -PossibleValueConfigurations @(
           @{ Name = "Yes" },
           @{ Name = "No" })
   }
   ```

1. 建立分類規則以偵測社會安全號碼：
**注意**  
下列規則表達式會搜尋模式為 XXX-XX-XXXX 的文字檔案。對於生產用途，請考慮使用更複雜的模式或結合多種偵測方法。

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       New-FSxFSRMClassificationRule -Name "Detect_SSN" -Property "ContainsPII" -PropertyValue "Yes" -Namespace "share" -ClassificationMechanism "Content Classifier" -ContentRegularExpression "\b\d{3}-\d{2}-\d{4}\b" 
   }
   ```

1. 執行分類：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Start-FSxFSRMClassification
   }
   ```

1. （選用） 設定持續分類以自動分類新檔案：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Set-FSxFSRMClassification -Continuous $true
   }
   ```

1. 檢查狀態 (1 表示已完成）：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Get-FSxFSRMClassification
   }
   ```

1. 分類完成後，您可以在 Windows File Explorer 中的檔案上按一下滑鼠右鍵，選取屬性，然後選擇分類索引標籤，以檢視指派給檔案的**分類****屬性**。此索引標籤會顯示檔案的所有分類屬性及其值。

## 建立檔案的保留政策
<a name="fsrm-creating-retention-policy"></a>

此範例顯示如何根據檔案的資料夾位置，依保留期間分類檔案，然後您可以搭配用戶端 PowerShell 指令碼來封存或刪除檔案。

**若要建立檔案的保留政策：**

1. 建立保留期間的分類屬性：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       New-FSxFSRMClassificationPropertyDefinition -Name "RetentionPeriod" -Type String -Description "File retention period" 
   }
   ```

1. 建立不同保留期的分類規則：
   + 資料夾法務文件下**法律文件**的 7 年保留期：

     ```
     Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
         New-FSxFSRMClassificationRule -Name "Legal_7Year" -Property "RetentionPeriod" -PropertyValue "7 years" -Namespace "share/Legal Documents" -ClassificationMechanism "Folder Classifier" 
     }
     ```
   + 資料夾 **Finance** 下財務記錄的 3 年保留期：

     ```
     Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
         New-FSxFSRMClassificationRule -Name "Finance_3Year" -Property "RetentionPeriod" -PropertyValue "3 years" -Namespace "share/Finance" -ClassificationMechanism "Folder Classifier" 
     }
     ```

   您也可以依檔案內容分類並搜尋字串，例如「保留期七年」。若要達成此目的，請使用 `ClassificationMechanism "Content Classifier"`和 `ContentString "Retention seven years"`。

1. 執行分類以套用保留屬性：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Start-FSxFSRMClassification
   }
   ```

1. （選用） 設定持續分類以自動分類新檔案：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Set-FSxFSRMClassification -Continuous $true
   }
   ```

1. 檢查狀態 (1 表示已完成）：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Get-FSxFSRMClassification
   }
   ```

1. 分類完成後，您可以在 Windows File Explorer 中的檔案上按一下滑鼠右鍵，選取屬性，然後選擇分類索引標籤，以檢視指派給檔案的**分類****屬性**。此索引標籤會顯示檔案的所有分類屬性及其值。

1. 將檔案分類為保留期間後，您可以使用用戶端 PowerShell 指令碼，根據檔案的`RetentionPeriod`屬性和存留期來封存或刪除檔案。例如，您可以掃描檔案系統，並將檔案的存留期與其保留期分類進行比較。如需詳細資訊，請參閱[檔案管理任務](fsrm-file-management.md)。

## 設定常見的儲存報告
<a name="fsrm-setting-up-storage-reports"></a>

本節說明如何建立兩個常用的儲存報告：大型檔案報告和依擁有者報告的檔案。

### 大型檔案報告
<a name="fsrm-large-files-report"></a>

此範例會建立每月報告，以識別大於 200 MB 的檔案。

**若要建立大型檔案報告：**

1. 建立排程的大型檔案報告：

   ```
   $schedule = @{
       Time = "2:00 AM"
       Monthly = @(1) # Run on the 1st of each month
   }
   
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ArgumentList $schedule -ScriptBlock {
       param($schedule)
       New-FSxFSRMStorageReport -Name "Monthly Large Files Report" -Namespace "share" -ReportType "LargeFiles" -LargeFileMinimum 200MB -ReportFormat "HTML","CSV" -ScheduleConfigurations $schedule 
   }
   ```

1. （選用） 立即執行報告以測試：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Start-FSxFSRMStorageReport -Name "Monthly Large Files Report"
   }
   ```

### 依擁有者報告的檔案
<a name="fsrm-files-by-owner-report"></a>

此範例會建立每週報告，顯示使用者使用的儲存體。

**若要依擁有者報告建立檔案：**

1. 依擁有者報告建立排程檔案：

   ```
   $schedule = @{
       Time = "3:00 AM"
       Weekly = @('Sunday')
   }
   
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ArgumentList $schedule -ScriptBlock {
       param($schedule)
       New-FSxFSRMStorageReport -Name "Weekly Files by Owner Report" -Namespace "share" -ReportType "FilesByOwner" -ReportFormat "HTML","CSV" -ScheduleConfigurations $schedule 
   }
   ```

1. （選用） 立即執行報告以測試：

   ```
   Invoke-Command -ComputerName $FSxWindowsRemotePowerShellEndpoint -ConfigurationName FSxRemoteAdmin -ScriptBlock {
       Start-FSxFSRMStorageReport -Name "Weekly Files by Owner Report"
   }
   ```

透過映射管理 D$ 共用來存取產生的報告。如需詳細資訊，請造訪 [存取儲存報告](fsrm-storage-reports.md#fsrm-storage-reports-accessing)。