none
Connect-PnPOnline : Invalid URI: The URI scheme is not valid RRS feed

  • Question

  • I'm going a bit crazy with this one. The following powershell snippet is giving me invalid URI errors. In troubleshooting I varied the script like so: 

    $sitelist = Import-Csv C:\Users\sp_farmadmin\Documents\modurllist.csv
    foreach($SiteURL in $sitelist)

    {
        #[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
        Connect-PnPOnline -Url $SiteURL
        write-output $siteurl
        }

    and I'm seeing errors following properly formatted url's

    https://obfuscated.sharepoint.com/teams/CorporateTraining                                                                                                                                                      
    Connect-PnPOnline : Invalid URI: The URI scheme is not valid.
    At line:9 char:5
    +     Connect-PnPOnline -Url $SiteURL
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Connect-PnPOnline], UriFormatException
        + FullyQualifiedErrorId : System.UriFormatException,SharePointPnP.PowerShell.Commands.Base.ConnectOnline

    I even tried this:

    cd C:\Users\sp_farmadmin\Documents\
    type modurllist.csv

    in powershell ise and I get a list of properly formatted url's

    Full ps1 follows:

    Any help appreciated!

    /Robin

    # Connect to the web holding the pages to modernize

    $sitelist = Import-Csv C:\Users\sp_farmadmin\Documents\modurllist.csv
    foreach($SiteURL in $sitelist)
    {
           Connect-PnPOnline -Url $SiteURL
           # Modernize page1.aspx and add the page keep/discard banner on the page
        ConvertTo-PnPClientSidePage -Identity home.aspx -AddPageAcceptBanner
        Remove-PnPFile $SiteURL/sitepages/home.aspx -force
        Rename-pnpfile $SiteURL/sitepages/migrated_home.aspx -TargetFileName home.aspx -force
        Set-PnPHomePage -RootFolderRelativeUrl SitePages/Home.aspx
       
    }
       $Web.Dispose();
    <#
    This code works fine by supplying individual url's the attempt at automation above does not work.
    Connect-PnPOnline -Url https://onehap.sharepoint.com/teams/Medical_Reimbursement_Policy_Committee
    # Modernize page1.aspx and add the page keep/discard banner on the page
    ConvertTo-PnPClientSidePage -Identity home.aspx -AddPageAcceptBanner
    Remove-PnPFile -serverrelativeurl /teams/Medical_Reimbursement_Policy_Committee/sitepages/home.aspx -force
    Rename-pnpfile -ServerRelativeUrl /teams/Medical_Reimbursement_Policy_Committee/sitepages/migrated_home.aspx -TargetFileName home.aspx -force
    Set-PnPHomePage -RootFolderRelativeUrl SitePages/Home.aspx
    #>


    Robin

    Thursday, September 5, 2019 10:03 PM

Answers

  • Hi  Robin,

    What’s the header for these site in the csv file? If the header is SiteURL, you need to change the URL parameter for Connect-PnPOnline as below:

    foreach($SiteURL in $sitelist)
    
    {
    
        Connect-PnPOnline -Url $SiteURL.SiteURL
    
        write-output $SiteURL
    
    }


    The CSV file as below:

    Best regards,

    Grace Wang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Robin4 Friday, September 6, 2019 2:44 PM
    Friday, September 6, 2019 6:12 AM
    Moderator

All replies

  • Hi  Robin,

    What’s the header for these site in the csv file? If the header is SiteURL, you need to change the URL parameter for Connect-PnPOnline as below:

    foreach($SiteURL in $sitelist)
    
    {
    
        Connect-PnPOnline -Url $SiteURL.SiteURL
    
        write-output $SiteURL
    
    }


    The CSV file as below:

    Best regards,

    Grace Wang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Robin4 Friday, September 6, 2019 2:44 PM
    Friday, September 6, 2019 6:12 AM
    Moderator
  • Hi Grace,

    Thanks for the suggestion. Yes my csv is as you illustrated. 

    Changed as follows and it works!

    Thanks so much!

    foreach($SiteURL in $sitelist)

    {

        Connect-PnPOnline -Url $SiteURL.URL

        write-output $SiteURL

    }


    • Edited by Robin4 Friday, September 6, 2019 2:46 PM
    Friday, September 6, 2019 12:05 PM