These days I had to do some tests with additional features we had to enable when a user creates his own “My Content” site. This means, create a “My Content” site, check, if everything is fine, do some corrections, remove the “My Content” site, remove the url in the profile of the user and test again.
To easily remove the “My Content” site and the url in the user profile, I created a small script to do the job:
param ( [string] $mySiteHostUrl, [string] $userLogon ) $site = Get-SPSite $mySiteHostUrl if ($site -ne $null) { $context = Get-SPServiceContext $site if ($context -ne $null) { $profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) if ($profileManager -ne $null) { $profile = $profileManager.GetUserProfile($userLogon) if ($profile -ne $null) { $personalSpace = $profile["PersonalSpace"].Value $pmMySiteHostUrl = $profileManager.MySiteHostUrl if ($pmMySiteHostUrl.EndsWith("/") -eq $true) { $pmMySiteHostUrl = $pmMySiteHostUrl.Substring(0 ,$pmMySiteHostUrl.Length-1) } $personalSpaceUrl = $pmMySiteHostUrl + $personalSpace Write-Host $personalSpaceUrl $personalSite = Get-SPSite $personalSpaceUrl if ($personalSite -ne $null) { $personalSite.Delete() Write-Host -ForegroundColor Green "Site" $personalSiteUrl "deleted." $profile["PersonalSpace"].Value = "" $profile.Commit() Write-Host -ForegroundColor Green "Cleared PersonalSpace property in the profile of user" $userLogon } else { Write-Host -ForegroundColor Red "Site" $personalSiteUrl "does not exist." } } } } else { Write-Host -ForegroundColor Red "Cannot get context!" } } else { Write-Host -ForegroundColor Red "Cannot get site at" $mySiteHostUrl }
Using this script, it was very easy to reset the environment.
Image may be NSFW.
Clik here to view.

Clik here to view.
