Unable to apply PNP template due to MFA RRS feed

  • General discussion

  • I have MFA enabled due to which whenver I run PNP powershell I have to user -useweblogin. But this is also not working when I loop through several sites. 


    requirement: 1.   Using PNP I have to create 50 Sitecollections :SharePoint online

    2. Apply PNPProvisioning Template
    3. Associate each site to HUB site. 

    4. Enable external Sharing for each. 


    When I ran below command it will fail after creating first site.  So I have to remove "start-sleep -s 1-" from the script. If I do that, it will create all the sites but "Provisioning template" is applying early without waiting for site to be created properly. Due to which it will fail applying template after 2 sites. 



    Not sure how to fix this. trying since 5days. no luck. 

    $TenantUrl = ""
    $myHubsite = ""
            Connect-pnpOnline -url $TenantUrl -Credentials -useweblogin
             $siteCollectionList = Import-Csv -Path "C:\sites.csv"
        #Loop through csv and provision site collection from each csv entry
        foreach ($siteCollection in $siteCollectionList)
            $SharePointUrl = $siteCollection.Url
            $SiteOwner = $siteCollection.Owner
            $Title = $siteCollection.Title
            $Template = $siteCollection.SiteTemplate
            $TimeZone = $siteCollection.TimeZone
            #Create site collection based on values above        
            New-PnPTenantSite -Owner $SiteOwner -Title $Title -Url $SharePointUrl -Template $Template -TimeZone $TimeZone  -Wait
            write-host "Site Collection $($SharePointUrl) Created Successfully!" -foregroundcolor Green
            Start-Sleep -s 10
            #connect to each site that was created earlier and then apply PNP template
            Connect-PnPOnline -Url $SharePointUrl -Credentials -useweblogin
            Apply-PnPProvisioningTemplate -Path C:\template8.xml
            write-host "Template applied $($SharePointUrl) Successfully!" -foregroundcolor Green
              #connect to tenant site again and then add each site to HUB
             Connect-pnpOnline -url $TenantUrl -Credentials -useweblogin
            Add-PnPHubSiteAssociation -Site $SharePointUrl -HubSite $myHubsite
            write-host "Hubsite association of $($SharePointUrl) completed Successfully!" -foregroundcolor Green
            Start-Sleep -s 1
            #Connect to Tenant site again and then connect to each site and enable external sharing
            Connect-PnPOnline -url $TenantUrl -Credentials -useweblogin
            Connect-PnPOnline -Url $SharePointUrl -Credentials -useweblogin
            Set-PnPSite -Identity $SharePointUrl -Sharing ExternalUserSharingOnly -Classification "Private External"
            write-host "External Sharing Enablement for $($SharePointUrl) completed Successfully!" -foregroundcolor Green
    • Changed type Joseph8888 Monday, March 2, 2020 4:51 PM
    Friday, February 28, 2020 7:50 PM

All replies