Create a MySite for all your users via PowerShell for SharePoint 2010

I was looking around to find a script that could provide all users from the organisation with a mysite.

Luckily, it didn’t take me very long to find Bugra Postaci’s blog!

He wrote this nice script:

#PowerShell Script - Create All Users Personel Sites - SharePoint 2010 #The scripts is distributet "as-is." Use it on your own risk.
#Add SharePoint PowerShell SnapIn if not already added if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")

$mysiteHostUrl = "<a href="http://my/">http://my</a>"
$personalSiteGlobalAdmin = "DOMAIN\padm"
$personalSiteGlobalAdminNot ="padm@bugrapostaci.com"
$personalSiteGlobalAdminDisplayName = "Personel Site admin"
$mysite = Get-SPSite $mysiteHostUrl

$context = [Microsoft.Office.Server.ServerContext]::GetContext($mysite)
$upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

$AllProfiles = $upm.GetEnumerator()

foreach($profile in $AllProfiles)
{

$DisplayName = $profile.DisplayName
$AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
#Add your restrictions for users.        if($Accountname -like "YourDomain*")
{
if($profile.PersonalSite -eq $Null)
{
write-host "Creating personel site for ", $AccountName
$profile.CreatePersonalSite()
#Adding an extra admin for personel sites                $pweb = $profile.PersonalSite.OpenWeb()
$pweb.AllUsers.Add($personalSiteGlobalAdmin,$personalSiteGlobalAdminNot,$personalSiteGlobalAdminDisplayName,$null);
$padm= $pweb.AllUsers[$personalSiteGlobalAdmin];
$padm.IsSiteAdmin = $true;
$padm.Update();
$pweb.Dispose();
write-host "Personal Site Admin has assigned"
}
else
{
write-host $AccountName ," has already personel site"
}
}
}
$mysite.Dispose();

He also has a script to delete mysites 😉

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.


2 thoughts on “Create a MySite for all your users via PowerShell for SharePoint 2010”

  1. This is not best practice, imo. Every clean MySite roughly 4.5MB storage in the database. If you create 2000 Mysites for example, and only 1000 of them are being used by end users, you have a data storage loss of 1000*4.5MB.

    1. That is correct.
      There are ways around that, like only adding a specific group or domain.

      I am in favor of using this script because you can create a myProfile page which works great as a who-is-who for an organisation that is just taking baby-steps into SharePoint.

Leave a Reply

%d bloggers like this: