9 Comments

  1. 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

    Reply

    • 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

      Reply

  2. 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”));
    }

    Reply

    • 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.

      Reply

  3. 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

    Reply

    • Have you tried to run this as administrator. I seems like the script was unable to find the User Profile Service.

      Reply

    • 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”

      Reply

      • Have sorted out my own issue. It was permission to the User profile service application for the executing user

        Reply

  4. @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.

    Reply

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.