How To Create A Subsite In Sharepoint 2007
Ever run into that problem where you keep adding webs to a single site collection then realize that your content database is growing to a size beyond belief? The logical next step would be to convert some of these webs to site collections so they can reside on their own content databases. Although this might seem like a difficult task, I will show you how to convert a SharePoint Sub-Site into a Site Collection using the power of PowerShell (PoSH). Windows PowerShell is an extensible automation engine from Microsoft consisting of a command-line shell and associated scripting language. The benefit of performing this conversion is that it allows in a scale-out scenario where each site collection can reside in its own database and potentially scaling-out even further by storing those databases on different physical SQL Servers. This way, the physical storage for site collections can be adjusted with minimal downtime and without affecting the logical URL structure of the site the end-user interacts with.
Install Windows PowerShell 2.0
PowerShell 2.0 is included with Windows 7 and Windows 2008 R2.
It is recommended to install PowerShell on the same machine that hosts the SharePoint server. However, PowerShell 2.0 has a remoting feature included that allows execution of scripts against remote machines as long as both machines are on the same domain or added to the TrustedHosts configuration setting.
Launch Windows PowerShell 2.0 ISE
When you install Windows PowerShell the setup program should also install a Start Menu shortcut for you; that shortcut can be found by clicking Start —> All Programs —> Accessories –> Windows PowerShell –> Windows PowerShell ISE.
When you do start Windows PowerShell you'll see something similar to this:
Script for Performing Conversion
The script for performing the conversion has been separated out into four separate scripts. Although multiple commands may be run at once it is recommended to run each command individually in order to view the results returned from each command's execution.
Script Legend
Red = Environment specific, must be replaced.
Green = Comment
First Script
The main functions of the first script are to rename the current Sub-Site, export its data, create a new Site Collection, and finally import the data into the new Site Collection.
When creating a new site collection ensure that it is being created on a new content database.
There are two ways of accomplishing this task:
1. Create a new content database through Central Administration
2. Use the stsadm createsiteinnewdb command.
Creation of a content database using Central Administration:
http://technet.microsoft.com/en-us/library/cc825314(office.14).aspx
Creation of a content database using the stsadm createsiteinnewdb command: http://technet.microsoft.com/en-us/library/cc262407.aspx
#Declare a variable and set its value to the Sub-Site name that will be converted to the Site Collection.
$filename = "Sub-Site Name"
#Declare a variable and set its value to the fully qualified domain name for the Sub-Site.
$url = "http://www.HostName.com/Sub-Site Name"
#Declare a variable and set its value to the user that's going to be the Site Collection owner.
$user = "DomainName\UserName"
#Declare a variable that will be used for identifying the Site Collection's owner e-mail address.
$email = "UserName@DomainName.com"
#Load the SharePoint Assembly to gain access to SharePoint's object model and be able to execute commands
#against SharePoint server.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#Declare a variable and set its value to the current site collection using the URL variable declared earlier
$site = new-object microsoft.sharepoint.spsite($url)
#Declare a variable and set its value to the current Sub-Site
$web = $site.OpenWeb()
#Declare a variable and set its value to the Web Template & Web Template ID which gets the name of the site definition #that was used to create the site. This is done because the same site definition will be used for creating the new Site #Collection otherwise some features will have to be activated manually.
$template = "$($web.WebTemplate)#$($web.WebTemplateid)"
#This command exports the site and sub-sites data into to a folder using the filename variable.
stsadm -o export -url "$url" -filename "$filename" -includeusersecurity -versions 4 -nofilecompression -quiet
#This command renames the current site by appending an "_ORIG" to its name.
stsadm -o renameweb -url "$url" -newname "$($filename)_ORIG"
#The addpath command specifies where new site collections can be created by using the URL parameter.
stsadm -o addpath -url "$url" -type explicitinclusion
#Create a site collection at the specified (URL) with the specified user as site collection owner and site collection #administrator and use the same template as the original site.
stsadm -o createsite -url "$url" -owneremail $email -ownerlogin $user -sitetemplate $template
#Import the site and sub-site data into the new site collection using the data file exported earlier.
stsadm -o import -url "$url" -filename "$filename" -includeusersecurity -nofilecompression –quiet
Second Script
Importing the data into the new Site Collection imports all of the groups and users that existed within the original site collection which may contain several groups and users that have no relationship with the newly created site collection. Therefore these groups and users must be removed. The second script takes care of this action.
#Declare a variable and set its value to the current site collection using the URL variable declared earlier
$site = new-object microsoft.sharepoint.spsite $url
#Declare a variable and set its value to the current Sub-Site
$web = $site.OpenWeb()
#Create a new variable and set its value to an empty hash table
$x = @{}
#Add all of the groups associated to all of the sites & sub-sites within the site collection to the (x) hash table.
$site.AllWebs|%{$_.Groups}|select Name,Id -unique |?{$x.Contains($_.Name) -eq $false}|%{$x.Add($_.Name,$_.Id)}
#Create a new variable and set its value to an empty hash table.
$y = @{}
#Iterate through all groups and only add the ones that aren't associated to the newly created site.
$web.SiteGroups|?{$x.Contains($_.Name) -eq $false}|?{$y.Contains($_.Name) -eq $false}|%{$y.Add($_.Name,$_.Id)}
#Remove the unnecessary groups.
$y.keys|%{$web.SiteGroups.RemoveById($y[$_])}
#Clear both hash tables
$x.Clear()
$y.Clear()
#Add all of the users associated to all of the sites & sub-sites within the site collection to the (x) hash table.
$site.AllWebs|%{$_.Users}|select Name,Id -unique |%{$x.Add($_.Id, $_.Name)}
$web.siteGroups | % {$_.Users} | select name, id -unique |?{$x.Contains($_.Id) -eq $false}| %{$x.Add($_.Id, $_.Name)}
#Iterate through all users and only add the ones that aren't associated to the newly created site.
$web.SiteUsers|select name, id -unique | ?{$x.Contains($_.Id) -eq $false}|%{$y.Add($_.Id, $_.Name)}
#Remove the unnecessary users.
$y.keys|%{$web.SiteUsers.RemoveById($_)}
New Site Collection Verification
To ensure that the new Site Collection has been created properly browse to both the original and new Site Collection, and cross check these items:
Home page appearance of both sites should be the same.
Verify that unnecessary groups and users have been removed from the new Site Collection
From the home page click on People and Groups –> More…
Compare both lists; the new site collection should have a smaller number of groups.
Comparing the All People lists should yield similar results.
Using the newly created Site Collection, go to the site settings page and verify that the site collection settings section is visible.
Third Script
The final step of this process is to delete the original site and any sub-sites that belong to it. In order to delete a site, any sub-sites must be deleted first. The third script performs this action by creating a function that iterates through the site's sub-sites and deletes each one before finally deleting the parent site.
#Create a function for deleting all sub-sites.
function delete-all-webs($url)
{
#This is used for display purposes, it prints the current sub-site that's going to be deleted.
"Delete web {0}" -f $url
#Create an xml object variable and set its value to all sub-sites that have been created #immediately below the site.
[xml]$xwebs = stsadm -o enumsubwebs -url $url
#Iterate through all sub-sites if they exist and delete each one.
if($xwebs.Subwebs.Count -gt 0){
foreach($web in $xwebs.Subwebs.subweb){
#Call the function for any child sub-sites that need to be deleted first.
delete-all-webs -url $web
}
}
#Command that performs the deletion
stsadm -o deleteweb -url $url
}
#Call the function to delete the sub-sites and parent site.
delete-all-webs -url "$($url)_ORIG"
To verify that the original sub-site no longer exists, browse to it using an internet explorer window making sure that the "_ORIG" is appended. If the deletion was performed correctly a "page not found" error should be displayed.
How To Create A Subsite In Sharepoint 2007
Source: https://www.lunavi.com/blog/converting-sharepoint-sub-sites-to-site-collections
Posted by: milsapmustrien.blogspot.com
0 Response to "How To Create A Subsite In Sharepoint 2007"
Post a Comment