Skip to content

Instantly share code, notes, and snippets.

@mikekunze
Created November 21, 2013 19:24
Show Gist options
  • Save mikekunze/7587946 to your computer and use it in GitHub Desktop.
Save mikekunze/7587946 to your computer and use it in GitHub Desktop.
This is a basic script that loads the powershell cmdlets for SharePoint and then creates a MySite if not exist for the user defined in $user
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$user = "mkunze"
$site = get-spsite("https://domain.com/mysites")
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profile = $upm.GetUserProfile($user)
if($profile.PersonalSite -eq $Null) {
$DisplayName = $profile.DisplayName
write-host "Creating personal site for $DisplayName, it doesnt exist yet"
$profile.CreatePersonalSite()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment