Today i had a problem in my development environment for my SharePoint Projects regarding User Profile Store. My user profile was a messed up and was not available for editing in central administration. When i searched for my profile it still there but not shown for administration. This was a really strange behavior because a couple of days it worked well. I added various new profile properties to my user profile service application. So the recreation of User Profile Service Application was not an option. Deletion of orphan or corrupted user profiles is not possible using Central Administration or even using avaliable PowerShell commands.
But there is a solution using PowerShell without compiled code. Using PowerShell everything what is avaliable in the server object model is avaliable. First of all two assemblies must be referenced.
These assemblies are:
- Microsoft.Office.Server (Core SharePoint Server Assembly)
- Microsoft.Office.Server.UserProfiles (UserProfile Assembly)
Those assemblies could be referenced using System.Reflection and the rest of the script is quite simple SharePoint Development. So get a context object, open profile service application get all use and delete them.
# Load required Assemblies for SharePoint Server and User Profile [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") # Central Adminstration URL or any Web Application $url = "http://mainframe:48248" # Create a new Context Object $contextWeb = New-Object Microsoft.SharePoint.SPSite("http://mainframe"); # Get the right Service Context $ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($contextWeb); # create a new connection to the UserProfileManager $UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext); # Ger all User Profiles $Profiles = $UserProfileManager.GetEnumerator(); # Loop through user profile foreach ($oUser in $Profiles ) { # Remove Profile $UserProfileManager.RemoveUserProfile($oUser.item("AccountName")); }
This script can be extended to delete only specific users from user profile information. At the end I was able to solve my problem. My User Profile was deleted and recreated on first access and due profile import. Everything worked fine.
In the old days you had to write some custom command line tool to address those batch update and deletion task. With the introduction of PowerShell to SharePoint any possible administrative task could be accomplished by just use scripting.
I would like to compare the account name in the site collection user profile table with the account name in the farm level user profile and a) get a list of all the site collection user profiles that differ from the farm and b) have an option to update the site collection information.
Are you aware of any articles that discuss doing something like this in powershell?
Thank you
Tricky questions. When you iterate over the profiles you can export that information to the file system and import it to excel. For the Site Collection thing you can create another PowerShell script that gets all items of the so called “User Information List”.
You can compare the user information using Excel.
For updating the information you should check out the following blog post: Updating SharePoint User Information
Hi, DEV Machine – just tried to run this via SharePoint 2010 Management Shell. After leaving it for a while, I get no error message, it just looks like it’s sitting there doing nothing
When checking UPS via CA, I am still seeing the same number of user profiles (5000+)
# Load required Assemblies for SharePoint Server and User Profile
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.UserProfiles”)
# Central Adminstration URL or any Web Application
$url = “http://yourserver:11237”
# Create a new Context Object
$contextWeb = New-Object Microsoft.SharePoint.SPSite(“http://yourserver);
# Get the right Service Context
$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($contextWeb);
# create a new connection to the UserProfileManager
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);
# Ger all User Profiles
$Profiles = $UserProfileManager.GetEnumerator();
# Loop through user profile
foreach ($oUser in $Profiles ) {
# Remove Profile
$UserProfileManager.RemoveUserProfile($oUser.item(“AccountName”));
}
Hi Cliff,
thank you for asking but unfortunately I never had such big amount of users to deal with. What you might could do is to add the following lines inside the foreach look:
Write-Host $oUser.item(“AccountName”);
# Remove Profile
$UserProfileManager.RemoveUserProfile($oUser.item(“AccountName”));
This should then output the progress of the deletion. Another issue here is that you might have to request the users in batches.
I’m trying this on SP2013. I’m getting…
New-Object : Exception calling “.ctor” with “1” argument(s): “UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.ApplicationProperties
ProfilePropertyCache does not have a482a0c7-4ba6-468c-b248-7809cb41a69e”
At line:1 char:23
+ $UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfil …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Have you tried to run this as administrator. I seems like the script was unable to find the User Profile Service.
Hi, I am getting the same error with SharePoint 2013
New-Object : Exception calling “.ctor” with “1” argument(s): “UserProfileApplicationNotAvailableException_Logging ::
UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have f8bd8d67-3daf-4240-8444-f2af9a35a88e”
Have sorted out my own issue. It was permission to the User profile service application for the executing user
@Erik,
Make account, which runs the script, Administrator for User profile Service Application and give the account Full Control in “Permissions” section for this service application.