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?
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.