Oct 07 2024 07:59 PM - edited Oct 15 2024 12:17 AM
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.
Oct 15 2024 12:51 PM
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
}