Set-AIPFileLabel
設定或移除檔案的 Azure 資訊保護標籤,並根據標籤組態或自訂許可權設定或移除保護。
Syntax
Set-AIPFileLabel
-LabelId <Guid>
[-JustificationMessage <String>]
[-Owner <String>]
[-PreserveFileDetails]
[-EnableTracking]
[-Path] <String[]>
[<CommonParameters>]
Set-AIPFileLabel
-LabelId <Guid>
[-JustificationMessage <String>]
-CustomPermissions <AIPCustomPermissions>
[-Owner <String>]
[-PreserveFileDetails]
[-Path] <String[]>
[<CommonParameters>]
Set-AIPFileLabel
[-JustificationMessage <String>]
[-RemoveLabel]
[-PreserveFileDetails]
[-Path] <String[]>
[<CommonParameters>]
Set-AIPFileLabel
[-JustificationMessage <String>]
[-RemoveLabel]
[-RemoveProtection]
[-PreserveFileDetails]
[-Path] <String[]>
[<CommonParameters>]
Set-AIPFileLabel
[-JustificationMessage <String>]
[-RemoveProtection]
[-PreserveFileDetails]
[-Path] <String[]>
[<CommonParameters>]
Set-AIPFileLabel
-CustomPermissions <AIPCustomPermissions>
[-Owner <String>]
[-PreserveFileDetails]
[-Path] <String[]>
[<CommonParameters>]
Description
針對 AIP 統一標籤用戶端, Set-AIPFileLabel Cmdlet 會設定或移除一或多個檔案的敏感度標籤。 當標籤設定為套用加密時,此動作會自動套用保護。
此外,當您使用 New-AIPCustomPermissions Cmdlet 建立為臨機操作保護原則物件時,您可以使用此 Cmdlet 來套用自訂許可權。
當命令成功執行時,可以取代任何現有的標籤或保護。
您可以非互動方式執行此 Cmdlet。 如需詳細資訊,請參閱 統一標籤用戶端系統管理員指南。
注意
在迴圈中執行 Set-AIPFileLabel Cmdlet 時,請在 Cmdlet 後面新增這兩行: [GC]::Collect ()
[GC]::WaitForPendingFinalizers ()
範例
範例 1:將「一般」標籤套用至目前沒有標籤的所有檔案
PS C:\> Get-AIPFileStatus -Path \\Finance\Projects\ | where {$_.IsLabeled -eq $False} | Set-AIPFileLabel -LabelId d9f23ae3-4321-4321-4321-f515f824c57b
FileName Status Comment
-------- ------ ------------
\\Finance\Projects\Image.jpg Success
\\Finance\Projects\Pricelist.pdf Success
\\Finance\Projects\Announcement.docx Success
\\Finance\Projects\Analysis.xlsx Success
此命令會先識別所有未使用 Get-AIPFileStatus Cmdlet 標記的檔案。 然後,這些檔案會藉由依識別碼指定「一般」標籤來加上標籤。
範例 2:將「一般」標籤套用至未加上標籤的.docx檔案
PS C:\> Get-ChildItem C:\Projects\*.docx -File -Recurse | Get-AIPFileStatus | where {$_.IsLabeled -eq $False} | Set-AIPFileLabel -LabelId d9f23ae3-1234-1234-1234-f515f824c57b
FileName Status Comment
-------- ------ ------------
C:\Projects\Analysis.docx Success
C:\Projects\Projects.docx Success
此命令會先使用Get-Child-Item識別C:\Projects資料夾中的所有.docx檔案 (及其子資料夾) ,然後從這些檔案中尋找未使用Get-AIPFileStatus Cmdlet 標記的檔案。 然後,產生的檔案會藉由依識別碼指定「一般」標籤來加上標籤。
注意
此命令會使用 FullName 的路徑別名, 讓 Get-Child-Item 可以搭配 Get-AIPFileStatus使用。
範例 3: (統一標籤用戶端只會) 將「一般」標籤套用至資料夾及其任何子資料夾中的所有檔案
PS C:\> Set-AIPFileLabel -Path C:\Projects\ -LabelId d9f23ae3-1324-1234-1234-f515f824c57b
FileName Status Comment
-------- ------ ------------
C:\Projects\Project1.docx Success
C:\Projects\Datasheet.pdf Success
C:\Projects\Image.jpg Success
C:\Projects\Analysis.xlsx Skipped No label to apply
C:\Projects\Dashboard.xlsx Success
此命令會在 Projects 資料夾及其任何子資料夾中的所有檔案上設定名為 「General」 的標籤。
如果 [一般] 標籤設定為套用加密,則使用此命令成功標記的檔案也會加密。 在此情況下,這些檔案的 Rights Management 擁有者 (具有 Rights Management 完整控制權限的人員) 就是執行 PowerShell 命令的使用者。
在此範例中,一個檔案未標示 (略過) ,因為它需要理由。 這可能是為了確保具有較高分類標籤或保護的檔案不會意外以較低的分類標籤覆寫或已移除保護的結果。
若要啟用此保護,必須將Office 365分類標籤原則設定為需要移除標籤或降低分類的理由。 當您接著在沒有 JustificationMessage 參數且標籤觸發理由的情況下執行此命令時,會略過批註「不套用標籤」的檔案。
範例 4: (統一標籤用戶端) 將「一般」標籤套用至單一檔案,這需要理由
PS C:\> Set-AIPFileLabel -Path \\Finance\Projects\Analysis.xlsx -LabelId d9f23ae3-1324-1234-1234-f515f824c57b -JustificationMessage 'The previous label no longer applies'
FileName Status Comment
-------- ------ ------------
\\finance\projects\analysis.xlsx Success
此命令會設定已加上較高分類標籤之檔案的「一般」標籤。 Office 365分類標籤原則設定為需要理由來移除標籤或降低分類。 由於命令包含理由訊息,因此已成功套用新的標籤。
範例 5: (統一標籤用戶端) 從檔案移除標籤
PS C:\> Set-AIPFileLabel C:\Projects\Analysis.docx -RemoveLabel -JustificationMessage 'The previous label no longer applies'
FileName Status Comment
-------- ------ ------------
C:\Projects\Analysis.docx Success
此命令會從名為 C:\Projects\Analysis.docx的檔案中移除現有的標籤,並指定強制理由訊息。
需要此理由方法,因為已啟用相關的 Office 365分類標籤原則設定,以要求移除標籤或降低分類的理由。
注意
如果您要移除的標籤是使用範本保護檔案,此命令會同時移除標籤和保護。
如果您要移除的標籤是使用自訂許可權保護檔案,此命令只會移除標籤。
範例 6: (統一標籤用戶端) 使用自訂許可權保護檔案
PS C:\> $permissions = New-AIPCustomPermissions -Users user1@contoso.com, user2@vanarsdel.com -Permissions Reviewer -ExpirationDate (Get-Date -Month 1 -Day 1 -Year 2020)
PS C:\> Set-AIPFileLabel C:\Projects\Analysis.docx -CustomPermissions $permissions
FileName Status Comment
-------- ------ ------------
C:\Projects\Analysis.docx Success
第一個命令會建立臨機操作保護原則物件,該物件會授與來自檢閱者許可權的不同組織許可權的使用者,並同時套用到期日。
第二個命令會使用預存臨機操作保護原則物件中的自訂許可權,來保護名為 Analysis.docx 的單一檔案。
範例 7: (統一標籤用戶端) 將標籤和自訂許可權套用至檔案
PS C:\> $permissions = New-AIPCustomPermissions -Users a@a.com, b@b.com -Permissions Reviewer
PS C:\> Set-AIPFileLabel C:\Projects\Analysis.docx -LabelId d9f23ae3-1324-1234-1234-f515f824c57b -CustomPermissions $permissions
FileName Status Comment
-------- ------ ------------
C:\Projects\Analysis.docx Success
第一個命令會建立臨機操作保護原則物件,該物件會授與來自檢閱者許可權的不同組織許可權的使用者,並同時套用到期日。
第二個命令會將標籤套用至名為 Analysis.docx 的單一檔案,並使用預存臨機操作保護原則物件中的自訂許可權來保護檔案。 如果標籤已設定為保護設定,則會由自訂許可權取代。
範例 8: (統一標籤用戶端) 從檔案移除保護
PS C:\> Set-AIPFileLabel C:\Projects\Analysis.docx -RemoveProtection
FileName Status Comment
-------- ------ ------------
C:\Projects\Analysis.docx Success
此命令會從名為 Analysis.docx的單一檔案中移除保護。
範例 9: (統一標籤用戶端) 移除檔案中的保護和標籤
PS C:\> Set-AIPFileLabel C:\Projects\Analysis.docx -RemoveProtection -RemoveLabel -JustificationMessage 'The previous label no longer applies'
FileName Status Comment
-------- ------ ------------
C:\Projects\Analysis.docx Success
此命令會從名為 Analysis.docx的單一檔案中移除標籤和自訂保護。 由於原則設定為需要理由才能移除標籤,因此也會提供理由原因,讓命令可以完成,而不會提示使用者原因。
參數
-CustomPermissions
指定儲存臨機操作保護原則的變數名稱,此原則是使用 New-AIPCustomPermissions Cmdlet 所建立。 臨機操作保護原則可用來保護具有自訂許可權的檔案或檔案。
Type: | AIPCustomPermissions |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-EnableTracking
指定此參數,以向檔追蹤入口網站註冊受保護的檔。
執行此 Cmdlet 和全域管理員的使用者接著可以追蹤受保護的檔,如有必要,請加以撤銷。 如需檔追蹤網站的詳細資訊,請參閱系統管理員指南中的設定和使用 Azure 資訊保護的檔追蹤。
如果標籤未套用保護,則會忽略此參數。
Type: | SwitchParameter |
Position: | named |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-JustificationMessage
降低分類標籤、移除標籤或移除保護的理由原因 (如果 Azure 資訊保護原則要求使用者提供此資訊)。 如果設定標籤會觸發理由,但未提供此原因,則不會套用標籤。 在此情況下,傳回的狀態為「已略過」並加上「需要理由」的註解。
Type: | String |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-LabelId
指定要套用標籤的識別 (識別碼) 。 當標籤有子標籤時,請一律只指定子標籤的識別碼,而不要指定父標籤的識別碼。
若要尋找標籤識別碼:
標籤識別碼值不會顯示在 Microsoft 365 合規性中心。 不過,您可以使用下列Office 365安全性 & 合規性中心 PowerShell 命令來尋找此值:Get-Label | Format-Table -Property DisplayName, Name, Guid
對於已套用標籤的檔案,您也可以執行 Get-AIPFileStatus Cmdlet 來識別 MainLabelId 或 SubLabelId) (標籤識別碼。
Type: | Guid |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Path
指定您要取得標籤和保護資訊的檔案的本機路徑、網路路徑或 SharePoint Server URL。
不支援萬用字元和 WebDav 位置。
針對 SharePoint 路徑,支援下列專案:
- SharePoint Server 2019
- SharePoint Server 2016
- SharePoint Server 2013
例如:
- C:\Folder\
- C:\Folder\Filename
- \\Server\Folder
- http://sharepoint.contoso.com/Shared%20Documents/Folder
當您以引號括住路徑值時,路徑可以包含空格。
Type: | String[] |
Aliases: | FullName, FileName |
Position: | 0 |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-PreserveFileDetails
指定此參數來保留修改日期, (Windows 和 SharePoint) ,並由您標籤的檔 (SharePoint) 值修改:
對於本機或網路檔案, 修改日期 的值會保持不變。
若為 SharePoint 檔案,[ 修改日期 ] 和 [修改後的值 ] 會保持不變。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-RemoveLabel
移除已套用至檔案的任何標籤。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-RemoveProtection
與下列專案相關: 僅限統一標籤用戶端
從檔案移除保護。 如果檔案已加上標籤,則不會移除標籤。
您必須擁有足夠的許可權,或是您組織的進階使用者,才能從檔案中移除保護。 如需詳細資訊,請參閱 設定 Azure Rights Management 和探索服務或資料復原的進階使用者。
使用 Set-AIPFileLabel PowerShell Cmdlet 從容器檔案中移除保護, (zip、 .rar、 .7z和 .pst) 。
注意
此移除保護功能預設為停用,必須先使用 Set-LabelPolicy Cmdlet 來啟用。
對於 .pst 檔案,5 GB 是此 Cmdlet 支援的最大檔案大小。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
輸入
System.String[]
輸出
Microsoft.InformationProtection.Powershell.AIP.Results.SetAIPFileResult