Data / Provision

Update content type of files in folder with system update

The script updates 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
powershell

#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
}

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.

Tool documentation & references

Keep exploring