当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:PowerShell 更改所有网站的访问请求电子邮件

作者:精品下载站 日期:2024-12-14 14:41:39 浏览:15 分类:玩电脑

SharePoint Online:PowerShell 更改所有网站的访问请求电子邮件


要求:在 SharePoint Online 中更改访问请求电子邮件。

[玩转系统] SharePoint Online:PowerShell 更改所有网站的访问请求电子邮件

PowerShell 在 SharePoint Online 中更改网站集的访问请求电子邮件:

访问请求允许用户请求访问 SharePoint 网站或网站集的权限。默认情况下,访问请求会发送到网站所有者的电子邮件地址。但是,您可能希望将此电子邮件地址更改为其他电子邮件地址或组。本文将指导您完成在 SharePoint Online 中更改访问请求电子邮件的步骤。

让我们使用 PowerShell 设置 SharePoint Online 网站集的访问请求电子邮件:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Set-SPOAccessRequestEmail([String]$SiteURL, [String]$AccessReqEmail)
{  
    Try{
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials

        #Get the Web and Sub Sites
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.Load($web.AllProperties)
        $Ctx.Load($Web.Webs)
        $Ctx.ExecuteQuery()
 
        #Check if the web has unique permissions
        $Web.Retrieve("HasUniqueRoleAssignments")
        $Ctx.ExecuteQuery()

        If($Web.HasUniqueRoleAssignments -eq $true)
        {
            #Set Access request Email
            $Web.RequestAccessEmail = $AccessReqEmail
            $Web.Update()
            $Ctx.ExecuteQuery()
            Write-Host -f Green "Access Request Email Updated for the Site:" $($SiteURL)
        }
        Else
        {
            Write-Host -f Yellow "Site '$($SiteURL)' is inhering Permissions from the Parent"
        }

        #Iterate through each subsite of the current web
        ForEach ($Subweb in $Ctx.Web.Webs)
        {
            #Call the function recursively 
            Set-SPOAccessRequestEmail -SiteURL $Subweb.url -AccessReqEmail $AccessReqEmail
        }
    }
    Catch {
        write-host -f Red "Error Updating Access Request Email!" $_.Exception.Message
    }
}

#Set parameter values
$SiteURL="https://Crescent.sharepoint.com"
$AccessReqEmail="[email protected]"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Call the function 
Set-SPOAccessRequestEmail -SiteURL $SiteURL -AccessReqEmail $AccessReqEmail

SharePoint Online:更改租户中所有网站的访问请求电子邮件地址

让我向您展示如何使用 PowerShell 脚本更改所有 SharePoint Online 网站的电子邮件地址。这是管理组织的电子邮件地址并使其在所有站点上保持一致的便捷方法。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"

#Function to set access request Email of a site/site collection
Function Set-SPOAccessRequestEmail([String]$SiteURL, [String]$AccessReqEmail)
{  
    Try{
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials

        #Get the Web and Sub Sites
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.Load($web.AllProperties)
        $Ctx.Load($Web.Webs)
        $Ctx.ExecuteQuery()
 
        #Check if the web has unique permissions
        $Web.Retrieve("HasUniqueRoleAssignments")
        $Ctx.ExecuteQuery()

        If($Web.HasUniqueRoleAssignments -eq $true)
        {
            #Set Access request Email
            $Web.RequestAccessEmail = $AccessReqEmail
            $Web.Update()
            $Ctx.ExecuteQuery()
            Write-Host -f Green "Access Request Email Updated for the Site:" $($SiteURL)
        }
        Else
        {
            Write-Host -f Yellow "Site '$($SiteURL)' is inhering Permissions from the Parent"
        }

        #Iterate through each subsite of the current web
        ForEach ($Subweb in $Ctx.Web.Webs)
        {
            #Call the function recursively 
            Set-SPOAccessRequestEmail -SiteURL $Subweb.url -AccessReqEmail $AccessReqEmail
        }
    }
    Catch {
        write-host -f Red "Error Updating Access Request Email!" $_.Exception.Message
    }
}

#Change Access Request Settings for All Site collections in the Tenant- Including Modern Team sites and communication sites
Function Change-SPOTenantAccessRequestEmail($AdminSiteURL)
{
    #Setup credentials to connect
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
    $Ctx.Credentials = $Credentials
 
    #Get the tenant object 
    $Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($ctx)
 
    #Get All Site Collections
    $SiteCollections=$Tenant.GetSitePropertiesFromSharePoint(0,$true)
    $Ctx.Load($SiteCollections)
    $Ctx.ExecuteQuery()

    #Iterate through Each site collection
    ForEach($Site in $SiteCollections)
    {
        Set-SPOAccessRequestEmail -SiteUrl $Site.Url -AccessReqEmail $AccessReqEmail
    }
}
 
#Set global Parameters
$AdminSiteUrl = "https://Crescent-admin.sharepoint.com"
$AccessReqEmail="[email protected]"

#Get Credentials to connect
$Cred= Get-Credential

#Call the function 
Change-SPOTenantAccessRequestEmail -AdminSiteURL $AdminSiteUrl

此脚本更改 SharePoint Online 中所有网站集的访问请求电子邮件。这是使用 PowerShell 为单个 SharePoint Online 网站更改访问请求电子邮件或禁用访问请求的另一篇文章:如何在 SharePoint Online 中更改访问请求电子邮件或禁用访问请求?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯