สร้างกลุ่ม SharePoint จากกลุ่ม Active Directory โดยใช้ PowerShell
ความต้องการ: แปลงกลุ่ม Active Directory เป็นกลุ่ม SharePoint!
วิธีแก้ปัญหา: การจัดการผู้ใช้ SharePoint ที่กลุ่ม Active Directory Security และภายใน SharePoint ก็มีข้อดีและข้อเสียเช่นกัน! ตอนนี้ เราต้องการย้ายจากกลุ่ม AD ไปยังกลุ่ม SharePoint ลองใช้ PowerShell เพื่อสร้างกลุ่ม SharePoint ใหม่จากกลุ่มความปลอดภัย Active Directory นี่คือสคริปต์ PowerShell ของฉัน:
สร้างกลุ่ม SharePoint จากกลุ่ม Active Directory:
ถ้าคุณมีกลุ่ม Active Directory อยู่แล้ว คุณอาจต้องการแปลงเป็นกลุ่ม SharePoint เพื่อลบการพึ่งพา AD Administrator
#Import Active directory & SharePoint PowerShell modules
Import-Module ActiveDirectory
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables for processing
$SiteURL="https://Intranet.crescent.com/"
$ADGroupName="SP13 Authors"
$SPGroupName="Content Authors"
$PermissionLevel="Full Control" #Permission to SPGroup
$Domain="Crescent" #AD Domain
#Get the Site collection's Root Web
$web = Get-SPWeb $SiteURL
#Check if Group Exists already
if ($web.SiteGroups[$SPGroupName] -ne $null)
{
write-Host "Group Name Already in the site!!" -ForegroundColor Red
}
else
{
#Create New SharePoint Group
$SPGroup = $web.SiteGroups.Add($SPGroupName, $web.Site.Owner, $web.Site.Owner, $null)
#Get the newly created group and assign permission to it
$SPGroup = $web.SiteGroups[$SPGroupName]
$RoleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($SPGroup)
$RoleDefinition = $web.RoleDefinitions[$PermissionLevel]
$RoleAssignment.RoleDefinitionBindings.Add($RoleDefinition)
$web.RoleAssignments.Add($RoleAssignment)
$web.Update()
Write-Host "New Group $SPGroupName has been created!"
#Get Members of AD Group
$ADGroupMembers = Get-ADGroupMember -Identity $ADGroupName | Select-Object -ExpandProperty SamAccountName
Write-host "Total Users Found in the AD Group:"$ADGroupMembers.Count
#Add Members to SPGroup from ADGroup
$ADGroupMembers | ForEach-Object {
#Convert to Domain\User format
$UserID = "$Domain\$_"
#Get Claims ID. E.g. Domain\User to i:0#.w|Domain\User
$UserClaimsID = (New-SPClaimsPrincipal -identity $UserID -IdentityType "WindowsSamAccountName").ToEncodedString()
$SPGroup.Users.Add($UserClaimsID,"", "", "")
Write-host "User Added from AD Group to SharePoint Group:" $UserClaimsID
}
}
โมดูล Active Directory PowerShell:
คุณต้องมี “โมดูล Active Directory สำหรับ Windows PowerShell” ในเซิร์ฟเวอร์สมาชิก Windows Server 2008/2012 ใช้ PowerShell cmdlet นี้เพื่อเพิ่มคุณสมบัตินี้:
Add-WindowsFeature RSAT-AD-PowerShell
หรือคุณสามารถไปที่: ตัวจัดการเซิร์ฟเวอร์ >> เพิ่มบทบาทและคุณสมบัติ >> เลือก “โมดูล Active Directory สำหรับ Windows PowerShell” ใต้เครื่องมือการดูแลระบบเซิร์ฟเวอร์ระยะไกล

