ค้นหาเว็บไซต์

วิธีใช้ RunWithElevatedPrivileges ในสคริปต์ PowerShell สำหรับ SharePoint


เราใช้วิธี RunWithElevatedPrivileges เพื่อเลียนแบบบัญชีระบบ (ข้อมูลประจำตัวของพูลแอปพลิเคชัน) ซึ่งได้รับสิทธิ์ในการควบคุมเต็มรูปแบบผ่านนโยบายผู้ใช้แอปพลิเคชันบนเว็บ นี่คือตัวอย่างของการใช้ 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 เพื่อเพิ่มผู้ดูแลไซต์คอลเลกชันใหม่

บทความที่เกี่ยวข้อง