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

สร้างกลุ่ม SharePoint โดยใช้ PowerShell


ความต้องการ: สร้างกลุ่ม SharePoint ใหม่โดยใช้ PowerShell

กลุ่ม SharePoint ทำให้การจัดการสิทธิ์ง่ายขึ้นโดยการกำหนดชุดผู้ใช้ให้กับกลุ่มและกำหนดระดับสิทธิ์ให้กับพวกเขาผ่านทางกลุ่ม มีกลุ่มเริ่มต้นที่ถูกสร้างขึ้นตามเทมเพลตไซต์ที่คุณเลือกขณะสร้างไซต์คอลเลกชัน เช่น เจ้าของ สมาชิก และผู้เยี่ยมชม ในโพสต์นี้ เราจะแสดงวิธีใช้ PowerShell เพื่อสร้างกลุ่ม SharePoint

PowerShell เพื่อสร้างกลุ่มความปลอดภัยของ SharePoint

การสร้างกลุ่มเป็นงานทั่วไปสำหรับผู้ดูแลระบบ SharePoint และนี่คือสคริปต์ของฉันในการสร้างกลุ่ม SharePoint ใหม่โดยใช้ PowerShell:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to Create new SharePoint Group
function Create-SPGroup
{  
    param ($SiteURL, $GroupName, $PermissionLevel, $GroupDescription)  

    try
    {
        #Get the Web
        $web = Get-SPWeb -Identity $SiteURL
        
        if($web -ne $null)
        {
            #Check if Group Exists already
            if ($web.SiteGroups[$GroupName] -ne $null)  
            {  
                write-Host "Group $GroupName exists Already!" -ForegroundColor Red 
            }  
            else  
            {  
                #Create SharePoint Group
                $Web.SiteGroups.Add($GroupName, $web.Site.Owner, $web.Site.Owner, $GroupDescription)  
                #Get the newly created group and assign permission to it
                $Group = $web.SiteGroups[$groupName]  
                $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)  
                $roleDefinition = $web.Site.RootWeb.RoleDefinitions[$permissionLevel]  
                $roleAssignment.RoleDefinitionBindings.Add($roleDefinition)  
                $web.RoleAssignments.Add($roleAssignment)  
                $web.Update()  

                write-Host "Group: $GroupName created successfully!" -ForegroundColor Green
            }  
 
            $web.Dispose() 
        }
    }
    catch [System.Exception]
    {
        write-host $_.Exception.ToString() -ForegroundColor Red 
    }
}

#Call the function to create Sharepoint group
Create-SPGroup "https://sales.crescent.com" "Sales Managers" "Edit" "Group for Sales Managers" 

สคริปต์นี้สร้างกลุ่มผู้ใช้ SharePoint โดยใช้ PowerShell คุณยังสามารถสร้างกลุ่มผู้ใช้ SharePoint จาก web UI: จะเพิ่มกลุ่มผู้ใช้ใหม่ใน SharePoint ได้อย่างไร

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