0
votes

I am trying to use PowerShell to create a new folder in a Teams document library, using the PnP Sharepoint Online module.

I can authenticate to the site in both PowerShell and in a browser. Then I run this code:

$cred = Get-Credential
$result = Add-PnPFolder -Folder "/sites/SalesDemo/Shared Documents/General/Acme Corp" -Name "testfolder" -Connection (Connect-PnPOnline -Url 'https://tenant.sharepoint.com' -Credentials $cred)

The result looks fine, showing the name, type, items/size, and last modified time, but when I view the site in SharePoint or in Teams, I do not see "testfolder". However, "testfolder" is returned when I run:

Get-PnPFolderItem -FolderSiteRelativeUrl "/sites/SalesDemo/Shared Documents/General/Acme Corp" -ItemType Folder -Connection (Connect-PnPOnline -Url 'https://tenant.sharepoint.com' -Credentials $cred)

Unfortunately, there are other folders in "Acme Corp" that are not returned.

Where is my "testfolder" being created?

enter image description here

enter image description here

1

1 Answers

1
votes

Update:

As discussed, when using Connect-PnPOnline, the url parameter should be the same as the site url where the library hosted, if it's hosting in specific site collection, the url should be:

https://Tenant.sharepoint.com/sites/SalesDemo

The testfolder should be located at the relative url:

/sites/SalesDemo/Shared Documents/General/Acme Corp

"Acnm Corp" should be a subfolder within /Shared Documents/General folder, the test folder should be there:

enter image description here