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

October 23rd, 2012 | Posted by Marijn in code | intranet | sharepoint 2010 | social

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"


$mysiteHostUrl = "<a href="http://my/">http://my</a>"
$personalSiteGlobalAdmin = "DOMAIN\padm"
$personalSiteGlobalAdminNot =""
$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
#Adding an extra admin for personel sites                $pweb = $profile.PersonalSite.OpenWeb()
$padm= $pweb.AllUsers[$personalSiteGlobalAdmin];
$padm.IsSiteAdmin = $true;
write-host "Personal Site Admin has assigned"
write-host $AccountName ," has already personel site"

He also has a script to delete mysites 😉

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

2 Responses

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

    • Marijn says:

      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: