Mar 10 2022 11:06 AM - edited Mar 10 2022 12:13 PM
Hi,
I am trying to add a series of folders to all the sites on a site collection with the below script:
#Config Variables
$SiteURL = "https://somesite.sharepoint.com/sites/pwa"
$CSVFilePath = "C:\Folders.csv"
$LibraryName = "Project Documents"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
$SubSites = Get-PnPSubWeb -Recurse
ForEach($Site in $Subsites)
{
#Get the CSV file
$CSVFile = Import-Csv $CSVFilePath
#Read CSV file and create folders
ForEach($Row in $CSVFile)
{
$FolderName = $Row.FolderName
#Create Folder
Add-PnPFolder -Name $Row.FolderName -Folder $LibraryName
Write-host "Ensured Folder:"$FolderName -f Green
}
}
But the output is always the same:
Add-PnPFolder : File Not Found.
At C:\Users\user\Desktop\Add folders to all sites.ps1:21 char:17
+ ... Add-PnPFolder -Name $Row.FolderName -Folder $LibraryName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Add-PnPFolder], ServerException
+ FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Files.AddFolder
Does anybody see where the problem is?
Thank you in advance