
The tag "small-basic" is for Technical questions about Microsoft Small Basic, the only text-based language and IDE built for students to learn to code
Please look for a more fitting tag as your question in not about Small Basic
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
We are planning to migrate the users and groups in active directory from one OU to another OU with Changing the group names.
i.e., Example: conso\testgroup this group changed to same domain conso\testgroup12
Above account having the access in SharePoint site at multiple locations.
Now AD changed the name to conso\testgroup12
Now it is fetch and reflected in SharePoint User Profiles but not in SharePoint sites.
There is 100 of Ad groups we have to change.
By manually we updated the group name in SharePoint by deleting old group and adding the new group.
But above method is not possible to upadte 100 groups manually.
Please suggest and update the powershell script for this activity.
We have tried the below articles and some powershell scripts, but there is no progress.
Articles::
Changes in Active Directory not reflected in SharePoint user info (microsoft.com)
AD Group Name Changes Not Updated After Profile Sync (microsoft.com)
AD Groups cannot be used to assign permissions in SharePoint (microsoft.com)
https://www.sharepointdiary.com/2015/05/update-user-display-name-in-sharepoint-2013-using-powershell.html
https://www.c-sharpcorner.com/Blogs/how-to-rename-a-sharepoint-group
https://godwinjogarajah.wordpress.com/2013/04/30/renaming-sharepoint-group-through-powershell/
https://support.microsoft.com/en-us/topic/99e44667-4c1a-496d-9dd3-7d7b0fee6179
Scripts::
[Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=Neutral, PublicKeyToken=71e9bce111e9429c")
$site = New-Object -TypeName Microsoft.SharePoint.SPSite -ArgumentList https://sharepoint
$group = $site.RootWeb.SiteUsers["conso\testgroup"]
$group.Name = "conso\testgroup12"
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$UserAccount="conso\testgroup"
$WebURL="https://sharepoint"
Get-SPUser -Identity $UserAccount -Web $WebURL
Set-SPUser -Identity "conso\testgroup12" -Web $WebURL -SyncFromAD
$user = Get-User 'conso\testgroup' | Rename-Object -NewName 'conso\testgroup12' -Passthru
Get-SPSite -Limit All | Get-SPWeb | Foreach-object {
Set-SPUser -Identity "conso\testgroup" -DisplayName "conso\testgroup12" -Web $_ }
The tag "small-basic" is for Technical questions about Microsoft Small Basic, the only text-based language and IDE built for students to learn to code
Please look for a more fitting tag as your question in not about Small Basic
Based on my research and testing, you can use the following code to rename SharePoint groups using PowerShell:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Function to Rename a Group
Function Rename-SPOGroup([String]$SiteURL, [String]$OldGroupName,[String]$NewGroupName)
{
Try {
#Get credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Group by name
$Group=$Ctx.web.SiteGroups.GetByName($OldGroupName)
If($Group -ne $Null)
{
#Rename the group
$Group.Title = $NewGroupName
$Group.Update()
$Ctx.ExecuteQuery()
write-host -f Green "Group '$OldGroupName' Renamed to '$NewGroupName' Successfully!" $_.Exception.Message
}
}
catch {
write-host "Error Renaming Group: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Variables
$SiteURL="https://Crescent.sharepoint.com/"
$OldGroupName = "Team Site Members"
$NewGroupName = "Marketing Managers"
#Call the function
Rename-SPOGroup -SiteURL $SiteURL -OldGroupName $OldGroupName -NewGroupName $NewGroupName
You can create a csv file that contains the SharePoint Groups Names that need to be renamed (OldName and NewName), then import the csv file through PowerShell and get the data in the file to rename the Groups in bulk.
Here is the code I tested, please refer to:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Function to Rename a Group
Function Rename-SPOGroup([String]$SiteURL, [String]$OldGroupName,[String]$NewGroupName)
{
#Get credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Group by name
$Group=$Ctx.web.SiteGroups.GetByName($OldGroupName)
If($Group -ne $Null)
{
#Rename the group
$Group.Title = $NewGroupName
$Group.Update()
$Ctx.ExecuteQuery()
write-host -f Green "Group '$OldGroupName' Renamed to '$NewGroupName' Successfully!" $_.Exception.Message
}
}
#Variables
$SiteURL="https://xxxxx.sharepoint.com/sites/zellatest"
$groups=Import-Csv -Path C:\Users\Administrator\Desktop\test.csv
foreach ($group in $groups)
{
$OldGroupName= $group.OldName
$NewGroupName=$group.NewName
Rename-SPOGroup -SiteURL $SiteURL -OldGroupName $OldGroupName -NewGroupName $NewGroupName
}
CSV file:
My test result:
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
When a user is updated in AD , the User profile sync will update it in the UPSA
From there two timers jobs update them on Site collection
But for Group update in AD are not synched to user profiles or site collections - this feature is NOT part of any timer jobs
hence we need to update it manually using PowerShell
Below script will update the display name of renamed AD group name in SharePoint by comparing with AD group name in active directory
---------------------------------------------------------------------------------------------------------------------------
param (
[Parameter (mandatory=$True)][string]$SiteCollection = $(throw "Missing SiteCollection (Eg: -SiteCollection http://sp/)"),
[Parameter (mandatory=$false)][switch]$ConfirmSync
)
clear
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
Write-Host "Loading SharePoint Powershell Snapin" -ForegroundColor Green
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
If($ConfirmSync -eq $true)
{
Write-Host "Warning ! The script is being executed in the read-write mode. Please review the report after the script execution" -ForegroundColor Magenta
Write-Host " "
sleep 2
}
else
{
Write-Host "Info : The script is being executed in the ReadOnly mode. Please review the report after the script execution" -ForegroundColor Green
Write-Host " "
sleep 2
}
try
{
$site=get-spsite $SiteCollection -ErrorAction stop
}
catch
{
write-host "Cannot find an SPSite object with Id or Url: " $SiteCollection -foregroundcolor Yellow
break;
}
$dateTime=Get-Date -format "dd-MMM-yyyy HH-mm-ss"
$ReportFile="Sync_SPADSecurityGroupInfo_Log"+"_"+ $dateTime + ".csv"
$ExceptionFile="Sync_SPADSecurityGroupInfo"+"_Exception"+ $dateTime + ".log"
$Header="SiteCollectionURL;UserLogin;SID_in_SP;Name_in_SP;Name_in_AD;Match;Sync"
Add-Content -Path $ReportFile -Value $Header
$AllDomainGroups = Get-SPUser -Web $SiteCollection -Limit ALL| where {$_.IsdomainGroup -eq $True}
write-host "=================================================="
write-host "Site collection:" $SiteCollection -NoNewline -ForegroundColor Magenta
Write-Host " || " -NoNewline
write-host "No of AD Groups:" $AllDomainGroups.count -ForegroundColor Magenta
write-host "=================================================="
Write-Host ""
foreach ($domaingroup in $AllDomainGroups)
{
[String]$UserLogin=$domaingroup.UserLogin
if ($UserLogin.StartsWith("c:0+.w|s"))
{
$Name_in_SP = $domaingroup.DisplayName
$SID_in_SP = ($UserLogin.Split("|")[1]).ToString()
try
{
$objSID = New-Object System.Security.Principal.SecurityIdentifier ($SID_in_SP)
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
$Name_in_AD = $objUser.Value
}
catch [Exception]
{
write-host "Exception occured while fetching the details of" $UserLogin " from Active directory. Please review the exception log file"
write-host $_.exception
$GroupresolutionException="Exception occured while fetching the details of" +$UserLogin+"from Active directory"
Add-Content -Value $GroupresolutionException -Path $ExceptionFile
Add-Content -Value $_.exception -Path $ExceptionFile
Add-Content -Value "=====================================================" -Path $ExceptionFile
Add-Content -Value "" -Path $ExceptionFile
}
if ($Name_in_SP -eq $Name_in_AD)
{
$match="Yes"
}
else
{
$match="No"
}
Write-host "Fetching group"$domaingroup -ForegroundColor Yellow
write-host "UserLogin :" $UserLogin
write-host "SID_in_SP :" $SID_in_SP
Write-host "Name_in_SP:" $Name_in_SP
write-host "Name_in_AD:" $Name_in_AD
write-host "Match :" $match
write-host ""
if ($match -eq "No" -and $ConfirmSync -eq $true)
{
write-host "Synching.." -ForegroundColor Green
try
{
$domaingroup.DisplayName = $Name_in_AD
$domaingroup.Update()
}
catch [Exception]
{
write-host "Exception occured while updating the details of" $UserLogin " on Site collection $SiteCollection. Please review the exception log file"
write-host $_.exception
$GroupUpdateException="Exception occured while updating the details of" + $UserLogin + " on Site collection $SiteCollection"
Add-Content -Value $GroupUpdateException -Path $ExceptionFile
Add-Content -Value $_.exception -Path $ExceptionFile
Add-Content -Value "=====================================================" -Path $ExceptionFile
Add-Content -Value "" -Path $ExceptionFile
}
$Header="SiteCollectionURL;UserLogin;SID_in_SP;Name_in_SP;Name_in_AD;Match;Sync"
$MessageSync=$SiteCollection+";"+$UserLogin+";"+$SID_in_SP+";"+$Name_in_SP+";"+$Name_in_AD+";"+$match+";Yes"
Add-Content -Path $ReportFile -Value $MessageSync
}
else
{
$MessageNoSync=$SiteCollection+";"+$UserLogin+";"+$SID_in_SP+";"+$Name_in_SP+";"+$Name_in_AD+";"+$match+";No"
Add-Content -Path $ReportFile -Value $MessageNoSync
}
}
else
{
Write-host "Fetching group"$domaingroup ".." -ForegroundColor Yellow -NoNewline
write-host ".. Skipping !" -ForegroundColor Cyan
write-host ""
$MessageSkip=$SiteCollection+";"+$UserLogin+";"+$SID_in_SP+";N/A;N/A;N/A;N/A"
Add-Content -Path $ReportFile -Value $MessageSkip
}
}
-------------------------------------------------------------------------------------------------