I have some simple code to add a couple of folders to a SharePoint Site library. Locally it runs smoothly in seconds, but in a runbook the same code runs increasingly slower, resulting in getting the runbook suspended. Looking at the error messages, it seems that somehow it even goes into a loop of repeating commands. Max. 3 folders are created. In Azure and local I have the same module ( PnP.Powershell 1.2.0) Any tips are very welcome.

$dcSharePointRootUrl = "https://XXXX.sharepoint.com/sites/"
$SiteUrl = "13Test"
$credential = Get-AutomationPSCredential -Name "XXX" ;
$targetSite = $dcSharePointRootUrl + $SiteUrl
Connect-PnPOnline -Url  $targetSite -Credentials $credential 
$targetFolder =  "/sites/"+ $SiteUrl + "/Shared Documents"
Add-PnPFolder -Name "Technical proposal" -Folder $targetFolder
Add-PnPFolder -Name "Procurement" -Folder $targetFolder
Add-PnPFolder -Name "Engineering" -Folder $targetFolder
Add-PnPFolder -Name "Commercial proposal" -Folder $targetFolder

Error messages: Add-PnPFolder : A file or folder with the name https://xxxx.sharepoint.com/sites/13Test/Shared Documents/Technical proposal already exists. At line:16 char:1 + Add-PnPFolder -Name "Technical proposal" -Folder $targetFolder +

CategoryInfo : WriteError: (:) [Add-PnPFolder], ServerException +
FullyQualifiedErrorId :

1 Answer 1


a runbook needs a var, like : $dummy = Add-PnPFolder -Name "Technical proposal" -Folder $targetFolder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.