Update content type of files in folder with system update
Summary
Update content type with system update option for all files in a folder within a library to a custom content type to avoid updating modified and modified by properties.
Implementation
- Open Windows PowerShell ISE
- Create a new file
- Copy a script below
#Config Variables
$SiteURL = "https://tenant.sharepoint.com/sites/Estimator"
$ListName = "Documents"
$FolderServerRelativePath= "/sites/Estimator/Shared Documents/LineManagement"
$NewContentType = "Legal"
Connect-PnPOnline -url $SiteURL -Interactive
Try {
#Get all files from folder
Get-PnPListItem -List $ListName -PageSize 2000 | Where {$_.FieldValues.FileRef -like "$FolderServerRelativePath*" -and $_.FileSystemObjectType -eq "File" } | ForEach-Object {
Write-host $_.FieldValues.FileRef
Set-PnPListItem -UpdateType SystemUpdate -List $ListName -ContentType $NewContentType -Identity $_
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Reshmee Auckloo |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.