Created
March 26, 2013 11:50
-
-
Save ciphertxt/5244828 to your computer and use it in GitHub Desktop.
Adds all users in the UPA to a given site collection. Handy for pre-populating a User Information List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") | |
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") | |
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | |
# Enter your SharePoint site URL here... | |
$site = new-object Microsoft.SharePoint.SPSite("http://intranet"); | |
$web = Get-SPWeb "http://intranet"; | |
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site); | |
$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext) | |
$AllProfiles = $ProfileManager.GetEnumerator() | |
$allProfileCounter = 0; | |
$usrProfileCounter = 0; | |
foreach($profile in $AllProfiles) | |
{ | |
$allProfileCounter = $allProfileCounter + 1; | |
$DisplayName = $profile.DisplayName | |
$AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value | |
$shortAccountName = $AccountName.Substring($AccountName.IndexOf("\") + 1); | |
$web.EnsureUser($AccountName); | |
write-host "Added $DisplayName ($shortAccountName) to site"; | |
$usrProfileCounter = $usrProfileCounter + 1; | |
} | |
write-host "Found $usrProfileCounter users out of $allProfileCounter profiles"; | |
write-host "Finished." | |
$site.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment