A constructed URL does not work in Runbook but does in ISE when connecting to a sharepoint site

Jurgen Verhelst 331 Reputation points
2020-12-25T03:43:04.66+00:00

Hi,

Trying to use a runbook in Azure Automation for creating and modifying sharepoint sites

An URL I construct using a static and a variable part when connecting to the newly created site works on desktop ISE but not in the runbook

New-PNPSite -type Teamsite -Title $SiteColTitle -Alias $SiteColName
Connect-PnPOnline -url -Site "https://fqdn/sites/$SiteColName" -Credentials  $myCred

throws this error;

Connect-PnPOnline : A positional parameter cannot be found that accepts argument 'https://fqdn/sites/Test_003'. 
At line:25 char:1
+ Connect-PnPOnline -url -Site "https://fqdn/sites/$Si ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Connect-PnPOnline], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,PnP.PowerShell.Commands.Base.ConnectOnline

I do see the new site in sharepoint admin active sites, so it is created, but connecting to it afterwards fails

When trying with the full URL it does work but I want to reuse the $SiteColName and not have to make a $SiteColURL as well...

does constructing an URL work differently in a runbook then in ISE on my desktop?

Thanks!

merry Xmas! :)

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. Baker Kong-MSFT 3,801 Reputation points
    2020-12-25T06:14:33.46+00:00

    Hi @JurgenVerhelstezNetworking-5458,

    I suggest you use the following syntax:

    Connect-PnPOnline -Url  
    

    Not Connect-PnPOnline -url -Site "https://fqdn/sites/$SiteColName". Based on the doc, there is no -site paremeter.

    Best Regards,
    Baker Kong


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. trevorseward 11,711 Reputation points
    2020-12-25T14:55:57.473+00:00

    In addition to @Baker Kong-MSFT 's answer, you shouldn't be using username/password. I wrote an end-to-end on how to use Managed Identities and Client Certificate for PnP provisioning.

    https://thesharepointfarm.com/2020/12/sharepoint-azure-pnp-provisioning/


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.