0

I am using SharePointPnPPowerShellOnline version 3.29.2101.0 and have successfully connected and authenticated to my Teams SP site. However, I get the following error when I try to create SP folders: "Add-PnPFolder : Cannot contact site at the specified URL ... There is no Web named ...". Any suggestions? enter image description here

4
  • 1
    Are you seeing the same thing with the replacement 'PnP.PowerShell' module? powershellgallery.com/packages/PnP.PowerShell
    – user6024
    Commented Jan 25, 2021 at 16:55
  • I think, in your script, Shared Documents is the name of the document library where you are creating folders at, but it's not a site or sub-site name. Remove the library name from variable $URL and try again. Commented Jan 25, 2021 at 18:16
  • @TrevorSeward - I ran Get-Module and it shows I already have PnP.PowerShell 1.2.0.
    – 12AX7
    Commented Jan 25, 2021 at 19:21
  • @MatiurRahman - I removed the folder part of the URL and the error was "File Not Found". This is the underlying SharePoint site for MS Teams. Also, the code I have executing has been working for some time now until I upgraded SP PnP PS.
    – 12AX7
    Commented Jan 25, 2021 at 19:21

2 Answers 2

1

The following script worked for me, that is,TestFolder was created in "Shared Documents" library root. The site was created when an MS Team was created (MS Teams default site).

Import-Module -Name SharePointPnPPowerShellOnline -Verbose

#Config Variables
$SiteURL = "https://mytenant.sharepoint.com/sites/MSTeamsSite"
 
Connect-PnPOnline -Url $SiteURL -SPOManagementShell

Add-PnPFolder -Name "TestFolder" -Folder "/Shared%20Documents"

3
  • I ran your script and got this error: "Add-PnPFolder : Server relative urls must start with SPWeb.ServerRelativeUrl".
    – 12AX7
    Commented Jan 25, 2021 at 22:22
  • I'm using PnpPowerShellOnline 3.21.2005.2, Not sure if it has anything to do. However, the error msg that your are getting indicates that you need to add the relative path like "/sites/your team site name/Shared%20Documents" Commented Jan 26, 2021 at 13:12
  • Thanks for your help @MatiurRahman. I can't get it to work in my tenant with a relative path or otherwise.
    – 12AX7
    Commented Jan 26, 2021 at 21:49
1

You need to pass the credential on site level. Put the URL of the site instead of the library for the parameter $URL.

Here is a sample script:

$SiteUrl = <SiteURL>
$Username = <AdminAccount>
$Password = <Password>
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $(convertto-securestring $Password -asplaintext -force)

Connect-PnPOnline -Url $SiteUrl -Credential $cred

#Skip this line if you already have Folder General in the Shared Documents library
Add-PnPFolder -Name General -Folder Shared%20Documents

#Create SubFolders in Shared Documents > General
Add-PnPFolder -Name "Teams Training" -Folder Shared%20Documents/General

Your Answer

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

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