Showing posts with label Site Collection. Show all posts
Showing posts with label Site Collection. Show all posts

Friday, June 16, 2017

Create Site Collection in New Content Database in SharePoint 2010 / 2013

If you have a requirement where you need to Create a Site Collection in New Content Database, refer following PowerShell Script:

add-pssnapin Microsoft.SharePoint.PowerShell
$url = "http://sitecollection_link"
$ContentDatabase = "Content_DB_Name"
$WebsiteName = "New Site Collection Title"
$WebsiteDesc = "New Site Collection Description"
$Template = "STS#0" #It is for team site (use STS#1 for blank site)
$PrimaryLogin = "Domain\username1"
$SecondaryLogin = "Domain\username2"

New-SPSite -Url $url –ContentDatabase $ContentDatabase -Name $WebsiteName –Description $WebsiteDesc  -Template $Template -OwnerAlias $PrimaryLogin -SecondaryOwnerAlias $SecondaryLogin



Following script will create new content database and create site collection in newly created database. It is with parameters and also handles errors, so looks little longer :P


add-pssnapin Microsoft.SharePoint.PowerShell

#Set following parameters
$WebsiteName = "Test Site"

#Verify following parameters
$DbServer = "SQLServer"
$WebAppUrl = "http://webapplink"
#Uncomment if you are using managed path
#$ManagedPath = "path"
$DBName = "WSS_Content_" + $WebsiteName
$PrimaryLogin = "Domain\UserName"
$SecondaryLogin = "Domain\UserName"
$MaxSiteCount = 1
$WarningSiteCount = 0
$ContentDatabase = $null

#Create new content database
try
{
    $ContentDatabase = Get-SPContentDatabase $DBName -ErrorAction ignore
    if($ContentDatabase -eq $null)
    {
        New-SPContentDatabase -Name $DBName -DatabaseServer $DbServer -WebApplication $WebAppUrl -MaxSiteCount $MaxSiteCount -WarningSiteCount $WarningSiteCount -ErrorAction Stop
        Write-Host "Database Created Successfully" -ForegroundColor Green
        $ContentDatabase = Get-SPContentDatabase $DBName       
    }
    else
    {
        Write-Host "Database already exist." -ForegroundColor Red
    }


    #Set Parameters
    $url = $WebAppUrl + "/sites/" +$WebsiteName
    #Uncomment if you are using managed path
    #$url = $WebAppUrl + "/" + $ManagedPath + "/" +$WebsiteName
    $WebsiteDesc = "FieldDocs for year " +$WebsiteName
    $Template = "STS#1"

    #Create new site collection
    try
    {
        $site= $null
        $site = Get-SPSite $url -ErrorAction ignore   
       
        if($site -eq $null)
        {
            New-SPSite -Url $url –ContentDatabase $ContentDatabase -Name $WebsiteName –Description $WebsiteDesc  -Template $Template -OwnerAlias $PrimaryLogin -SecondaryOwnerAlias $SecondaryLogin -ErrorAction Stop
            Write-Host "Site Collection Created Successfully" -ForegroundColor Green
        }
        else
        {
            Write-Host "Site Collection already exist." -ForegroundColor Red
            $site.Dispose()
        }       
    }
    catch
    {
        Write-Host "Error in site collection creation" -ForegroundColor Red
    }
}
catch
{
    Write-Host "Error in database creation" -ForegroundColor Red
}


Monday, March 25, 2013

Use custom favicon in SharePoint 2010 Master Page


Follow the steps to use custom favicon in SharePoint 2010 Master Page
  1. Open SharePoint Designer 2010
  2. Locate master page file in SharePoint Designer 2010
    Note: Default location of master page files: All Filesà_catalogsàmasterpage
  3. Right click on the default master page file
    Note: By default v4.master is default master page file
  4. Check Out master page file and open in Advanced Mode by right clicking to the file
  5. Find “SharePoint:SPShortcutIcon” tag in HEAD section of the content
  6. Replace IconUrl value with custom icon file
    Example:
    <SharePoint:SPShortcutIcon runat="server" IconUrl="/images/custom_icon.ico" />
  7. Save file and check in all the changes
  8. Publish and Approve the changes
Contact Me for any technical help related with SharePoint 2010.

Wednesday, March 20, 2013

Empty Site Collection Recycle Bin using SharePoint 2010 Management Shell (PowerShell)

Follow the steps to Empty Site Collection Recycle Bin using SharePoint 2010 Management Shell (PowerShell):
1.   Open SharePoint 2010 Management Shell with Run as administrator

2.   Modify Site collection Url in following script and execute:

$sitecollectionUrl = "http://site:port/sitecollection"

$siteCollection = New-Object Microsoft.SharePoint.SPSite($sitecollectionUrl)
write-host("Items to be deleted : " +$siteCollection.RecycleBin.Count.toString())
$now = Get-Date
write-host("Deleting started at " +$now.toString())
$siteCollection.RecycleBin.DeleteAll();
$now = Get-Date
write-host("Deleting completed at " +$now.toString())
$siteCollection.Dispose(); 

Contact Me for any technical help related with SharePoint 2010.

Tuesday, March 19, 2013

Create new SharePoint List Item using SharePoint 2010 Management Shell (PowerShell)

Follow the steps to create new SharePoint List Item using SharePoint 2010 Management Shell (PowerShell):
1.       Open SharePoint 2010 Management Shell with Run as Administrator

2.       Modify and execute following script:

#Web absolute URL where list exists
$webURL = "<http://site:port/site/subsite>" 

#SPList Name where items to be added
$listName = "<List Name>" 

#Get the SPWeb object and save it to a variable
$web = Get-SPWeb $webURL 

#Get the SPList object to retrieve the List
$list = $web.Lists[$listName] 

#Create a new item
$newItem = $list.Items.Add() 

#Add properties to this list item
$newItem["Title"] = "Title Text"
$newItem["Description"] = "Description Text" 

#Update the object so it gets saved to the list
$newItem.Update()

$web.Dispose()

Contact Me for any technical help related with SharePoint 2010.

Monday, March 18, 2013

Determine Site / Site Collection Size (SharePoint 2007 & 2010)


1.   Open SharePoint 2010 Management Shell / Windows Command Prompt with Runas Administrator

2.   Enter below command to access "stsadm.exe" and press enter
cd "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN"
(Replace 14 by 12 for SharePoint 2007)

3.   Type below command and press enter
STSADM.exe -o enumsites -url "<Url of the web application>"
4.   Command will give text output where you can see site/site collection details like:
a.   Url
b.   Ower
c.   Content Database
d.   Storage Used MB
e.   Storage Warning MB
5.   Modify the command with text file path to get output in text file
Example:
STSADM.exe -o enumsites -url "<Url of the web application>" > c:\SiteDetails.txt

Contact Me for any technical help related with SharePoint 2010.