0

I am due to go live with a SharePoint 2013 custom Intranet to 2000 users. The business has asked that I auto populate the MySite profiles. Can this be done?

Short of impersonating users using LDAP I have no idea how to do this. PowerShell Script maybe?

  • Can you define what you mean by auto populate the MySite profiles? In general though, yes you can use Powershell. Let me know what you are trying to do and I may have something you can use. – Todd Aug 5 '14 at 20:00
  • Hi, thanks for the comment, when i say auto populate, currently the user has to visit the MySite in order for their profile to be populated and to be searchable with the sharepoint search service. the business does not want to rely on an employee having to visit the MySite for their profile to be populated with fields from AD, hope this helps. – Csharper Aug 5 '14 at 20:16
  • Are you looking to have the users MySite provisioned without them actually starting the process by visiting the site for the first time? – Jason Aug 6 '14 at 2:02
1

We developed a powershell social module for our 2013 deployment that would allow us to do several things including pre-provision personal site collections and have people following the CEO by default. Let me know if you have any questions on how to use this. And to place credit correctly, this was written mostly by a teammate of mine and not by myself (posted with his permission).

#Adapted from http://gallery.technet.microsoft.com/office/Pre-Provision-SharePoint-ec781ee9

Function New-SPSitePersonalSites
{
<#
    .SYNOPSIS
        New-SPSitePersonalSites is an advanced function which can be used to create personal site for each user in a SharePoint site.
    .DESCRIPTION
        New-SPSitePersonalSites is an advanced function which can be used to create personal site for each user in a SharePoint site.
        Maximum users can be specified to limit the number of personal sites created per execution.
    .PARAMETER  SiteUrl
        The specified site URL.
    .PARAMETER  MaxUsers
        Optional - The specified number of iterations.
    .PARAMETER  FollowUser
        Optional - Follow a user after creating the personal site
    .EXAMPLE
        C:\PS>  New-SPSitePersonalSites -SiteURL "http://sp2010:8888/sites/TopSite2" -MaxUsers 5 -FollowUser "contoso\jones"

        This command shows how to create personal site for 5 users in site "http://sp2010:8888/sites/TopSite2" and have them follow "contoso\jones".
#>
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory = $True,Position=0)]
        [String]$SiteURL,
        [Parameter(Mandatory = $False,Position=1)]
        [int]$MaxUsers,
        [Parameter(Mandatory = $False,Position=2)]
        [String]$FollowUser
    )

    if ($maxUsers -eq 0) {

        $title = "Continue?"
        $message = "Do you want to create personal sites for all users in $siteURL ?"

        $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
            "Creates personal sites for all users in $siteURL."

        $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
            "Exits script. You may specify -MaxUsers to limit the number of sites created."

        $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)

        $result = $host.ui.PromptForChoice($title, $message, $options, 0) 

        switch ($result)
            {
                0 {}
                1 {Return}
            }
    }

    #Add "Microsoft.SharePoint.PowerShell" Snapin
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
    {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }
    #Load "Microsoft.Office.Server" Assembly
    [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") | Out-Null 
    #Get SharePoint site
    $Site = Get-SPSite -Identity $SiteURL
    #Get service context
    $context = Get-SPServiceContext -Site $site
    $upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
    $AllProfiles = $upm.GetEnumerator()
    #Create personal site for each user


    $i = 0
    $j = 0
    $profileCount = $upm.count
    $startTime = Get-Date
    Write-Host $startTime
    foreach($profile in $AllProfiles)
    {

        if ($maxUsers -ne 0 -and $i -ge $maxUsers) {
            write-host -foregroundcolor "Green" "$i Iteations complete. Stopping for now."
            break
        }
        if ($maxUsers -ne 0) {
            $count = $i + 1
            write-progress -activity "Creating Personal Sites" -status "Running: $count of $maxUsers" -percentComplete ($count / $maxUsers * 100)       
        }

        # Progress bar for all users
        if ($maxUsers -eq 0) {
            $count = $j + 1
            write-progress -activity "Creating Personal Sites" -status "Running: $count of $pofilecount" -percentComplete ($count / $profileCount * 100)
        }

        $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
        #write-host $accountname
        Try
        {
            if ($accountName -notlike "*admin*" -and $accountName -notlike "*IUSR_*" -and $accountName -notLike "*IWAM_*") {
                if($profile.PersonalSite -eq $Null)
                {
                    write-host "Creating personal site for $AccountName" 
                    $profile.CreatePersonalSite()       
                    write-host "Personal Site Admin has assigned"
                    if ($followuser) {
                        $a = New-SPFollowUser -SiteURL $siteURL -user $accountname -usertofollow $followuser                    
                        if ($a = "OK") {
                            write-host "$AccountName is now following $followuser"
                        } 
                        elseif ($a = "AlreadyFollowing") {
                            write-host "$AccountName is already following $followuser"
                        } else {
                            write-error $a
                        }
                    }
                    $i++
                }
                else
                {
                    # Write-Warning "$AccountName already has personel site"
                }
            }
        }
        Catch
        {
            Write-Error "Failed to create personal site for '$AccountName'"
        }
        $j++
    } 
    $endTime = Get-Date
    Write-Host $endTime
    $Site.Dispose();

}

Function New-SPSitePersonalSites-Threaded
{
<#
    .SYNOPSIS
        New-SPSitePersonalSites is an advanced function which can be used to create personal site for each user in a SharePoint site.
    .DESCRIPTION
        New-SPSitePersonalSites is an advanced function which can be used to create personal site for each user in a SharePoint site.
        Maximum users can be specified to limit the number of personal sites created per execution.
    .PARAMETER  SiteUrl
        The specified site URL.
    .PARAMETER  MaxUsers
        Optional - The specified number of iterations.
    .PARAMETER  FollowUser
        Optional - Follow a user after creating the personal site
    .EXAMPLE
        C:\PS>  New-SPSitePersonalSites -SiteURL "http://sp2010:8888/sites/TopSite2" -MaxUsers 5 -FollowUser "contoso\jones"

        This command shows how to create personal site for 5 users in site "http://sp2010:8888/sites/TopSite2" and have them follow "contoso\jones".
#>
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory = $True,Position=0)]
        [String]$SiteURL,
        [Parameter(Mandatory = $False,Position=1)]
        [int]$MaxUsers,
        [Parameter(Mandatory = $False,Position=2)]
        [String]$FollowUser,
        [Parameter(Mandatory = $False,Position=3)]
        [int]$MaxThreads = 10
    )

    if ($maxUsers -eq 0) {

        $title = "Continue?"
        $message = "Do you want to create personal sites for all users in $siteURL ?"

        $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
            "Creates personal sites for all users in $siteURL."

        $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
            "Exits script. You may specify -MaxUsers to limit the number of sites created."

        $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)

        $result = $host.ui.PromptForChoice($title, $message, $options, 0) 

        switch ($result)
            {
                0 {}
                1 {Return}
            }
    }

    #Add "Microsoft.SharePoint.PowerShell" Snapin
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
    {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }
    #Load "Microsoft.Office.Server" Assembly
    [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") | Out-Null 
    #Get SharePoint site
    $Site = Get-SPSite -Identity $SiteURL
    #Get service context
    $context = Get-SPServiceContext -Site $site
    $upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
    $AllProfiles = $upm.GetEnumerator()
    #Create personal site for each user


    $i = 0
    $j = 0
    $profileCount = $upm.count

    $workerScript = {
        param (
            [Parameter(Mandatory = $True,Position=0)]
            [string]$SiteURL,
            [Parameter(Mandatory = $True,Position=1)]
            [string]$User,
            [Parameter(Mandatory = $False,Position=2)]
            [string]$followUser
        )
        #Add "Microsoft.SharePoint.PowerShell" Snapin
        if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
        {
            Add-PSSnapin "Microsoft.SharePoint.PowerShell"
        }
        #Load "Microsoft.Office.Server" Assembly
        [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") | Out-Null 
        #Get SharePoint site
        $Site = Get-SPSite -Identity $SiteURL
        #Get service context
        $context = Get-SPServiceContext -Site $site
        $upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
        $profile = $upm.GetUserProfile($user)
        $accountName = $profile.AccountName
        write-host "Creating personal site for $AccountName" 
        $profile.CreatePersonalSite()       
        write-host "Personal Site Admin has assigned"
        if ($followuser) {
            $a = New-SPFollowUser -SiteURL $siteURL -user $accountname -usertofollow $followuser                    
            if ($a = "OK") {
                write-host "$AccountName is now following $followuser"
            } 
            elseif ($a = "AlreadyFollowing") {
                write-host "$AccountName is already following $followuser"
            } else {
                write-error $a
            }
        }
        $Site.Dispose();        
    }

    $startTime = Get-Date
    Write-Host $startTime
    foreach($profile in $AllProfiles)
    {

        if ($maxUsers -ne 0 -and $i -ge $maxUsers) {
            write-host -foregroundcolor "Green" "$i Iteations complete. Stopping for now."
            break
        }
        if ($maxUsers -ne 0) {
            $count = $i + 1
            write-progress -activity "Creating Personal Sites" -status "Running: $count of $maxUsers" -percentComplete ($count / $maxUsers * 100)       
        }

        # Progress bar for all users
        if ($maxUsers -eq 0) {
            $count = $j + 1
            write-progress -activity "Creating Personal Sites" -status "Running: $count of $pofilecount" -percentComplete ($count / $profileCount * 100)
        }

        $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
        #write-host $accountname
        Try
        {
            if ($accountName -notlike "*admin*" -and $accountName -notlike "*IUSR_*" -and $accountName -notLike "*IWAM_*") {
                if($profile.PersonalSite -eq $Null)
                {
                    $stuff = start-job -scriptblock $workerScript -argumentList $siteurl, $profile.AccountName, $followUser
                    while ($(get-job -state 'Running').count -ge $MaxThreads) {
                        sleep 1
                    }

                    $i++
                }
                else
                {
                    # Write-Warning "$AccountName already has personel site"
                }
            }
        }
        Catch
        {
            Write-Error "Failed to create personal site for '$AccountName'"
        }
        $j++
        Get-Job -State "Completed" | Receive-Job
    } 

    $endTime = Get-Date
    Write-Host $endTime
    $Site.Dispose();

}

Function New-SPPersonalSite
{
<#
    .SYNOPSIS
        New-SPPersonalSite is an advanced function which can be used to create personal site for each user in a SharePoint site.
    .DESCRIPTION
        New-SPPersonalSite is an advanced function which can be used to create personal site for each user in a SharePoint site.
        Maximum users can be specified to limit the number of personal sites created per execution.
    .PARAMETER  SiteUrl
        The specified site URL.
    .PARAMETER  User
        The specified user.
    .PARAMETER  FollowUser
        Optional - Follow a user after creating the personal site
    .EXAMPLE
        C:\PS>  New-SPPersonalSite -SiteURL "http://sp2010:8888/sites/TopSite2" -User "contoso\smith" -FollowUser "contoso\jones"

        This command shows how to create personal site for "contoso\smith" in site "http://sp2010:8888/sites/TopSite2" and have them follow "contoso\jones".
#>
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory = $True,Position=0)]
        [String]$SiteURL,
        [Parameter(Mandatory = $True,Position=1)]
        [String]$User,
        [Parameter(Mandatory = $False,Position=2)]
        [String]$FollowUser
    )

    #Add "Microsoft.SharePoint.PowerShell" Snapin
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
    {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }
    #Load "Microsoft.Office.Server" Assembly
    [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") | Out-Null 
    #Get SharePoint site
    $Site = Get-SPSite -Identity $SiteURL
    #Get service context
    $context = Get-SPServiceContext -Site $site
    $upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
    # Get the user profile
    $userprofile = $upm.GetUserProfile($user)

    if ($userProfile) {
        $AccountName = $userprofile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value


        #write-host $accountname
        #Try
        #{
            #Create personal site for the user
            if($userprofile.PersonalSite -eq $Null)
            {
                write-host "Creating personal site for $AccountName" 
                $userprofile.CreatePersonalSite()
                write-host "Personal Site Admin has assigned"
                if ($followuser) {
                    $a = New-SPFollowUser -SiteURL $siteURL -user $accountname -usertofollow $followuser                    
                    if ($a = "OK") {
                        write-host "$AccountName is now following $followuser"
                    } 
                    elseif ($a = "AlreadyFollowing") {
                        write-host "$AccountName is already following $followuser"
                    } else {
                        write-error $a
                    }
                }
            }
            else
            {
                Write-Warning "$AccountName already has personel site"
            }
        # }
        # Catch
        # {
            # Write-Error "Failed to create personal site for '$AccountName'"
        # }
    }
    $Site.Dispose();
}

#Adapted from http://gallery.technet.microsoft.com/office/Pre-Provision-SharePoint-ec781ee9
# http://social.msdn.microsoft.com/Forums/en-US/02c3996b-a5eb-4e3f-ab21-dc4853f5c05d/how-to-unfollow-all-the-sites-with-powershell-script-at-sharepoint-2013?forum=sharepointadmin
# http://blog.sharedove.com/adisjugo/index.php/2013/07/11/following-a-user-on-behalf-of-someone-in-sharepoint-2013-social/

Function New-SPSiteFollowUser
{
<#
        .SYNOPSIS
            New-SPSiteFollowUser is an advanced function which can be used to force all users in a SharePoint site to follow another user.
        .DESCRIPTION
            New-SPSiteFollowUser is an advanced function which can be used to force all users in a SharePoint site to follow another user.
        .PARAMETER  SiteUrl
            The specified site URL.
        .PARAMETER  UserToFollow
            The specified user to follow.
        .EXAMPLE
            C:\PS>  New-SPSiteFollowUser -SiteURL "http://sp2010:8888/sites/TopSite2" -UserToFollow "contoso\smith"

        This command shows how to force each user in site "http://sp2010:8888/sites/TopSite2" to follow "contoso\smith".
#>
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory = $True,Position=0)]
        [String]$SiteURL,
        [Parameter(Mandatory = $True,Position=1)]
        [String]$UserToFollow
    )

    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
        {
            Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }

    $site = Get-SPSite $SiteURL

    $Context = Get-SPServiceContext($site)

    $upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
    $AllProfiles = $upm.GetEnumerator()
    #Get all users
    foreach($profile in $AllProfiles)
    {
        $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
        #write-host $accountname
        if ($accountname -ne $UserToFollow) {
            if($upm.UserExists($AccountName))
            {
                $userProfile = $upm.GetUserProfile($AccountName)

                $followingManager = new-object Microsoft.Office.Server.Social.SPSocialFollowingManager($userProfile, $Context)

                $actorInfo = new-object Microsoft.Office.Server.Social.SPSocialActorInfo
                $actorInfo.ActorType = "User"
                $actorInfo.AccountName = $UserToFollow

                $followingManager.Follow($actorInfo);
                #$followingManager.StopFollowing($actorInfo);
            }
        }
    }
}

Function New-SPFollowUser
{
<#
        .SYNOPSIS
            New-SPFollowUser is an advanced function which can be used to follow a user in the SharePoint site.
        .DESCRIPTION
            New-SPFollowUser is an advanced function which can be used to follow a user in the SharePoint site.
        .PARAMETER  SiteUrl
            The specified site URL.
        .PARAMETER  User
            The specified user.
        .PARAMETER  UserToFollow
            The specified user to follow.
        .EXAMPLE
            C:\PS>  New-SPFollowUser -SiteURL "http://sp2010:8888/sites/TopSite2" -User "contoso\jones" -UserToFollow "contoso\smith"

        This command shows how to have "contoso\jones" follow "contoso\smith" in "http://sp2010:8888/sites/TopSite2".
#>
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory = $True,Position=0)]
        [String]$SiteURL,
        [Parameter(Mandatory = $True,Position=1)]
        [String]$User,
        [Parameter(Mandatory = $True,Position=2)]
        [String]$UserToFollow
    )

    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
        {
            Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }

    $site = Get-SPSite $SiteURL

    $Context = Get-SPServiceContext($site)

    $profileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($Context)

    $upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
    $AllProfiles = $upm.GetEnumerator()
    #Get all users
    foreach($profile in $AllProfiles)
    {
        $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
        if ($accountname -eq $User) {
            if($profileManager.UserExists($AccountName))
            {
                $userProfile = $profileManager.GetUserProfile($AccountName)

                $followingManager = new-object Microsoft.Office.Server.Social.SPSocialFollowingManager($userProfile, $Context)

                $actorInfo = new-object Microsoft.Office.Server.Social.SPSocialActorInfo
                $actorInfo.ActorType = "User"
                $actorInfo.AccountName = $UserToFollow

                $a = $followingManager.Follow($actorInfo)
                #$followingManager.StopFollowing($actorInfo);
            }
        }
    }
}


Function Get-SPPersonalSiteCount
{
<#
        .SYNOPSIS
            Get-SPPersonalSiteCount is a function to get the count of personal sites.
        .DESCRIPTION
            Get-SPPersonalSiteCount is a function to get the count of personal sites.
        .PARAMETER  SiteUrl
            The specified site URL.
        .EXAMPLE
            C:\PS>  Get-SPPersonalSiteCount -SiteURL "http://sp2010:8888/sites/TopSite2"

        This command shows how to get the count of personal sites in "http://sp2010:8888/sites/TopSite2".
#>
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory = $True,Position=0)]
        [String]$SiteURL
    )

    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
        {
            Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }

    $site = Get-SPSite $siteURL

    $Context = Get-SPServiceContext($site)

    $upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
    $AllProfiles = $upm.GetEnumerator()
    #Get all users
    $i = 0
    foreach($userprofile in $AllProfiles)
    {
        $AccountName = $userprofile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
        if($upm.UserExists($AccountName))
        {
            if($userprofile.PersonalSite -ne $Null)
            {
                $i++
            }
        }
    }

    write-host "$i"
}
  • Hi Todd thats awesome, i take it a pre-requisit for the script to run correctly is the AD sync service to be setup in SharePoint and a full sync to be performed atleast once so that when Microsoft.Office.Server.UserProfiles.UserProfileManager is used it can obtain the list of users, is this correct? because if not i dont see how the script would connect o AD and generate the personal sites, thanks for this useful script. – Csharper Aug 6 '14 at 18:58
  • Just so you know, my sites, like those provisioned in the script and my site profile pages are two different, but related, things. See office.microsoft.com/en-us/sharepoint-server-help/… – Tom Resing Aug 6 '14 at 19:47
  • 1
    @TomResing - yeah, after posting that I read the comments again and realized I had misread the question. – Todd Aug 7 '14 at 21:03
  • @Csharper - Yes, the AD sync service is needed first. – Todd Aug 7 '14 at 21:04
  • Hi todd i havent forgot about this question im in the process of setting up a new environment i will get back to you soon. – Csharper Aug 11 '14 at 19:45
2

There are a couple potential issues with user profiles and active directory related to missing information. One is just a configuration issue. Another has to do with how users are considered active in SharePoint.

Import or Sync

First, I recommend that you check your connection to Active Directory. In SharePoint 2013, you have two options.

  1. Active Directory Import

  2. User Profile Sync

If you're using Active Directory Import, it's pretty straight forward. Spencer Harbar has a good explanation of it here: First Look: SharePoint Server 2013 Active Directory Import

If you're going the User Profile Sync route, there's a good chance the Service may not be correctly configured. I recommend reading Spencer Harbar's excellent article: Rational Guide to implementing SharePoint Server 2010 User Profile Synchronization

Active Users

The other question has to deal with a hidden list and when users are added to it. In some cases, users are not visible in the hidden list until they log in. This question and answer provide some detail on that situation.

If this hidden user list is the issue you're running into, I would go back and study up on the import or sync articles I link to above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.