SharePoint için PowerShell Betiklerinde RunWithElevatedPrivileges Nasıl Kullanılır?


Web uygulaması kullanıcı politikası aracılığıyla TAM kontrol erişim haklarına sahip olan Sistem Hesabını (Uygulama havuzu kimliği) taklit etmek için RunWithElevatedPrivileges yöntemini kullanırız. PowerShell ile RunwithElevatedPrivileges kullanımına bir örnek:


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!"   
 
 }
)  

Bu PowerShell örneği, yeni site koleksiyonu yöneticisi eklemek için SharePoint'te yükseltilmiş ayrıcalıklarla çalıştırmayı kullanır.

İlgili makaleler