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

[玩转系统] 如何在 SharePoint 的 PowerShell 脚本中使用 RunWithElevatedPrivileges?

作者:精品下载站 日期:2024-12-14 13:42:40 浏览:12 分类:玩电脑

如何在 SharePoint 的 PowerShell 脚本中使用 RunWithElevatedPrivileges?


我们使用 RunWithElevatedPrivileges 方法来模拟系统帐户(应用程序池身份),该帐户通过 Web 应用程序用户策略被授予完全控制访问权限。以下是将 RunwithElevatedPrivileges 与 PowerShell 结合使用的示例:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
{

    #Define the parameter values: Site collection URL and user account to remove
    $siteURL =  "https://sharepoint.crescent.com/sites/sales"
    $userAccount = "crescent\Salaudeen" 
  
    #Get the RootWeb
    $web= Get-SPWeb $siteURL
    #Get the user acount - If doesn't exists ADD
    $user = $web.EnsureUser($userAccount)
 
    #Make the user as Site collection Admin
    $user.IsSiteAdmin = $true
    $user.Update()
 
    #Print a message
    Write-host "User: $($userAccount) has been added as site collection administrator!"   
 
 }
)  

此 PowerShell 示例使用 SharePoint 中的提升权限运行来添加新的网站集管理员。

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

取消回复欢迎 发表评论:

关灯