Forum Discussion
Using PnP PowerShell Apply label to items in this list or library
Hi All,
I am trying below PowerShell code for applying the retail policy to "Apply label to items in this list or library" but getting some Waring as mentioned below.
This is the ("30 Years Delete (Delete after 30 years)") default Label available for all list and libraris.
Kindly let me know how to Apply label to items in this list or library using PnP PowerShell.
Code:
Connect-PnPOnline -Url $siteURL -UseWebLogin
Set-PnPLabel -List "Documents" -Label "30 Years Delete (Delete after 30 years)" -SyncToItems $true
WARNING: Can not find compliance tag with value: Default. SiteSubscriptionId: 38ae3bcd-9579-4fd4-adda-b42e1495d55a
- LeonPavesicSilver Contributor
Hi harishpatil,
you are most probably getting the warning messagge because the Set-PnPLabel cmdlet is looking for a compliance tag with the value Default.
However, there is no compliance tag with that value.To try to resolve this issue, you can use the following PowerShell script to apply the 30 Years Delete (Delete after 30 years) label to all items in the Documents library:
Connect-PnPOnline -Url $siteURL -UseWebLogin # Get the compliance tag with the value "30 Years Delete (Delete after 30 years)" $complianceTag = Get-PnPComplianceTag -Label "30 Years Delete (Delete after 30 years)" # Apply the compliance tag to all items in the "Documents" library Set-PnPLabel -List "Documents" -Label $complianceTag -SyncToItems $true
This script will first get the compliance tag with the value 30 Years Delete (Delete after 30 years). Then, it will apply the compliance tag to all items in the Documents library.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
- harishpatilCopper ContributorHi Leaon,
Thank you very much for the quick response. I am getting below errors on specific line/command.
# Get the compliance tag with the value "30 Years Delete (Delete after 30 years)"
$complianceTag = Get-PnPComplianceTag -Label "30 Years Delete (Delete after 30 years)"
Get-PnPComplianceTag : The term 'Get-PnPComplianceTag' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At C:\OnlineMigration\Suresh\001-Comparison\Apply_Label_Retail_Policies.ps1:6 char:18
+ $complianceTag = Get-PnPComplianceTag -Label "30 Years Delete (Delete ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-PnPComplianceTag:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
And:
# Apply the compliance tag to all items in the "Documents" library
Set-PnPLabel -List "Documents" -Label $complianceTag -SyncToItems $true
Set-PnPLabel : Cannot bind argument to parameter 'Label' because it is null.
At C:\OnlineMigration\Suresh\001-Comparison\Apply_Label_Retail_Policies.ps1:9 char:39
+ Set-PnPLabel -List "Documents" -Label $complianceTag -SyncToItems $tr ...
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-PnPLabel], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,PnP.PowerShell.Commands.InformationManagement.SetLabel
Kindly help me how to get it resolve this issue.- LeonPavesicSilver Contributor
Hi harishpatil,
thanks for your Update.To resolve the issue you are facing, you will need to install the PnP PowerShell cmdlets.
You can install the PnP PowerShell cmdlets using the following steps:
- Open a PowerShell console.
- Run the following command:
Install-Module -Name SharePointPnPPowerShellOnline -Force
Once the PnP PowerShell cmdlets are installed, you should be able to run the PowerShell script without errors.
Connect-PnPOnline -Url $siteURL -UseWebLogin # Get the compliance tag with the value "30 Years Delete (Delete after 30 years)" $complianceTag = Get-PnPComplianceTag -Label "30 Years Delete (Delete after 30 years)" # Apply the compliance tag to all items in the "Documents" library Set-PnPLabel -List "Documents" -Label $complianceTag -SyncToItems $true
Please also restart PowerShell after installing the PnP PowerShell cmdlets in order for the changes to take effect.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic