Forum Discussion

SateeshKurella's avatar
SateeshKurella
Copper Contributor
Oct 08, 2024

Read the site collection URLs in excel/CSV and replace the Email ID.in the "Allow access requests"

Hi All,

 

I want to read Excel file which consist of Site collection URLs and replace the "Allow access requests" email ID.

 

I have developed below script,

 

#Config Variables
$CSVPath = "C:\Temp\ListofURLs.csv"

#Get Data from CSV
$CSVData = Import-CSV -Path $CSVPath

#Connect to PnP Online
Connect-PnPOnline -Url $Row.SiteURL -Interactive
#Get the Web
$Web = Get-PnPWeb
#Enable Access Request for the site to a Email ID
$Web.RequestAccessEmail = "email address removed for privacy reasons"
$Web.SetUseAccessRequestDefaultAndUpdate($False)
$Web.Update()
$Web.Context.ExecuteQuery()

 

But, It is replacing first URL in the CSV file but i have lot of URLs in the CSV file and how to do loop for all the URLs of site coleections to replace with the "email address removed for privacy reasons"

 

It's bit urgent please do the needful.

 

1 Reply

  • michalkornet's avatar
    michalkornet
    Iron Contributor

    Hi SateeshKurella, check the bolded lines, this time, the code should iterate through all the sites listed in the CSV.

     

    $CSVPath = "C:\Temp\ListofURLs.csv"

    #Get Data from CSV
    $CSVData = Import-CSV -Path $CSVPath

     

    foreach ($Row in $CSVData) {

    $siteUrl = $row.SiteUrl

    Connect-PnPOnline -Url $Row.SiteURL -Interactive
    #Get the Web
    $Web = Get-PnPWeb
    #Enable Access Request for the site to a Email ID
    $Web.RequestAccessEmail = "email address removed for privacy reasons"
    $Web.SetUseAccessRequestDefaultAndUpdate($False)
    $Web.Update()
    $Web.Context.ExecuteQuery()

     

    Disconnect-PnPOnline

    }

Resources