Skip to content

Commit ec172cb

Browse files
Dee ChristopherDee Christopher
Dee Christopher
authored and
Dee Christopher
committed
Added PowerShell Script To Sync SharePoint User Properties From AD
1 parent 4a11aa2 commit ec172cb

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
##############################################################################################################
2+
### Sync AD User Properties for each user on a Site Collection using PowerShell ###
3+
### Author: Rahul G. Babar ###
4+
##############################################################################################################
5+
6+
# Resource: https://sharepoint247.wordpress.com/2012/12/30/how-to-sync-ad-properties-of-users-in-a-sharepoint-site-collection/
7+
8+
$ver = $host | select version
9+
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
10+
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
11+
12+
#Read the Site Collection Url
13+
$siteUrl = Read-Host "Enter Site Collection Url (ex. http://SP2010Server:1234)"
14+
15+
if($siteUrl -ne $null -and $siteUrl -ne "")
16+
{
17+
$siteCollection = Get-SPSite $siteUrl
18+
if($siteCollection -ne $null)
19+
{
20+
foreach($web in $siteCollection.AllWebs)
21+
{
22+
Write-Host "Sync AD Properties for users on the web $web.Url"
23+
foreach($user in $web.AllUsers)
24+
{
25+
Set-SPUser -Identity $user -SyncFromAD -ErrorAction SilentlyContinue
26+
}
27+
}
28+
$siteCollection.Dispose();
29+
}
30+
else
31+
{
32+
Write-Error "Could not find site collection at url $siteUrl."
33+
}
34+
}
35+
else
36+
{
37+
Write-Error "Invalid Site Collection Url."
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
##############################################################################################################
2+
### Sync AD User Properties for each user on a Site Collection using PowerShell ###
3+
### Author: Rahul G. Babar ###
4+
##############################################################################################################
5+
6+
# Resource: https://sharepoint247.wordpress.com/2012/12/30/how-to-sync-ad-properties-of-users-in-a-sharepoint-site-collection/
7+
8+
$ver = $host | select version
9+
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
10+
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
11+
12+
#Read the Site Collection Url
13+
$siteUrl = Read-Host "Enter Site Collection Url (ex. http://SP2010Server:1234)"
14+
15+
if($siteUrl -ne $null -and $siteUrl -ne "")
16+
{
17+
$siteCollection = Get-SPSite $siteUrl
18+
if($siteCollection -ne $null)
19+
{
20+
foreach($web in $siteCollection.AllWebs)
21+
{
22+
Write-Host "Sync AD Properties for users on the web $web.Url"
23+
foreach($user in $web.AllUsers)
24+
{
25+
Set-SPUser -Identity $user -SyncFromAD -ErrorAction SilentlyContinue
26+
}
27+
}
28+
$siteCollection.Dispose();
29+
}
30+
else
31+
{
32+
Write-Error "Could not find site collection at url $siteUrl."
33+
}
34+
}
35+
else
36+
{
37+
Write-Error "Invalid Site Collection Url."
38+
}

0 commit comments

Comments
 (0)