Function Create-MySite
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $True,Position=2,valueFromPipeline=$true)][String]$Username,
[Parameter(Mandatory = $True,Position=1)][String]$MySiteRootURL
)
[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server");
$site=new-object Microsoft.SharePoint.SPSite($MySiteRootURL);
try
{
$serviceContext = Get-SPServiceContext $site;
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
if($upm.UserExists($Username) -eq $false)
{
Write-Host "User $Username was not found in the profile store." -f yellow;
return;
}
$userProfile = $upm.GetUserProfile($Username);
if($userProfile.PersonalSite -eq $Null)
{
Write-Host "Creating MySite for user $Username" -f darkyellow;
$userProfile.CreatePersonalSite();
Write-host "Successfully created MySite for user $Username" -f green;
}
else
{
Write-Host "User $Username already has a MySite." -f darkgreen;
}
}
catch
{
Write-Host "Encountered an error creating a MySite for user $Username. Error:"$_.Exception -f Red;
}
finally
{
$site.Dispose();
}
}
Create-MySite -MySiteRootURL "http://url" -Username "domain\user"
Wednesday, October 14, 2015
Friday, October 9, 2015
Powershell script remove contenttypes from list
#Get site object and specify name of the library to look for in each site
$site = Get-SPSite http://URL
$lookForList = "ListName"
$ContentType = "CTName"
#Walk through each site and change content types on the list specified
$site | Get-SPWeb -Limit all | ForEach-Object {
write-host "Checking site:"$_.Title
#Check list exists
$docLibrary = $_.Lists[$lookForList]
#Remove unwanted content types from the list
if($docLibrary -ne $null)
{
$ctToRemove = $docLibrary.ContentTypes[$ContentType]
write-host "Removing content type" $ctToRemove.Name "from list" $docLibrary.Title
$docLibrary.ContentTypes.Delete($ctToRemove.Id)
$docLibrary.Update()
}
else
{
write-host "The list" $lookForList "does not exist in site" $_.Title
}
}
#Dispose of the site object
$site.Dispose()
Thursday, June 11, 2015
Export managed metadata
Get-SpServiceApplication | select DisplayName, ID
Get-SPServiceApplicationProxy | select DisplayName, ID
$mmsAppId = "GUID"
$mmsproxy = Get-SPServiceApplicationProxy -Identity GUID
Export-SPMetadataWebServicePartitionData -Identity $mmsAppId -ServiceProxy $mmsproxy -Path \\server\path\filename.bak
Get-SPServiceApplicationProxy | select DisplayName, ID
$mmsAppId = "GUID"
$mmsproxy = Get-SPServiceApplicationProxy -Identity GUID
Export-SPMetadataWebServicePartitionData -Identity $mmsAppId -ServiceProxy $mmsproxy -Path \\server\path\filename.bak
Migrate SharePoint social tag comments
Add-PSSnapin microsoft.sharepoint.powershell
$upaProxy = Get-SPServiceApplicationProxy GUID
$site = get-spsite #URL
$listName = #LISTNAME
foreach($web in $site.AllWebs){
$oldurl = ""
$newurl = ""
if($web.ParentWeb.Url -eq $site.url){
$list = $web.Lists[$listName]
$items = $list.items
foreach($item in $items)
{
if($item.xml -Like "*#RELPATH/PAGE.aspx, PAGETYPE*"){
$newurl = $web.url + "/" + $item.url
[System.uri]$newurl = $newurl
$newurl.AbsoluteUri
$oldurl = $newurl.AbsoluteUri
$oldurl = $oldurl -replace "SITE1", "SITE2"
$oldurl
Move-SPSocialComments -ProfileServiceApplicationProxy $upaProxy -OldUrl $oldurl -NewUrl $newurl.AbsoluteUri
}
}
}
}
$upaProxy = Get-SPServiceApplicationProxy GUID
$site = get-spsite #URL
$listName = #LISTNAME
foreach($web in $site.AllWebs){
$oldurl = ""
$newurl = ""
if($web.ParentWeb.Url -eq $site.url){
$list = $web.Lists[$listName]
$items = $list.items
foreach($item in $items)
{
if($item.xml -Like "*#RELPATH/PAGE.aspx, PAGETYPE*"){
$newurl = $web.url + "/" + $item.url
[System.uri]$newurl = $newurl
$newurl.AbsoluteUri
$oldurl = $newurl.AbsoluteUri
$oldurl = $oldurl -replace "SITE1", "SITE2"
$oldurl
Move-SPSocialComments -ProfileServiceApplicationProxy $upaProxy -OldUrl $oldurl -NewUrl $newurl.AbsoluteUri
}
}
}
}
Subscribe to:
Posts (Atom)