Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function Get-ScriptFiles{
#get all files
$query ="<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq></Where></Query><ViewFields><FieldRef Name='FileLeafRef' /><FieldRef Name='FileDirRef' /></ViewFields></View>"
$listItems = Get-PnPListItem -List $librarySiteAssets -Query $query
$libraryFolderPath = $librarySiteAssets + $scriptFolder
$folderPath = $PSScriptRoot + "\" + $folderFiles
foreach($listItem in $listItems){
#get all items in the folder 'Scripts'
if($listItem.FieldValues.FileDirRef -match $scriptFolder){
$scriptFile = $libraryFolderPath + "/" + $listItem.FieldValues.FileLeafRef
#Save file to locale
Get-PnPFile -Url $scriptFile -AsFile -Path $folder
#Add file data to provsioning template
$filePath = $folderPath + "\" + $listItem.FieldValues.FileLeafRef
Add-PnPFileToProvisioningTemplate -Path $provisioningTemplateFilePath -Source $filePath -Folder $libraryFolderPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment