PowerShell To Delete Site Collection

It’s easy to create a site collection using PowerShell as seen in an earlier post. Now let’s see how easy it is to delete a site collection using PowerShell cmdlet. It’s any day efficient way to create and delete site collections using PowerShell then use Central Administration GUI.

For the purpose of testing we will

· Create a site collection named 2Delete using a site template STS#0

· Delete a site collection named 2Delete

  1. New site collection created using SharePoint 2010 Management Shell.
    clip_image002
  2. Site collection created. as per confirmation. Delete site collection using SharePoint 2010 Management Shell.
    clip_image004
  3. Press ENTER.
    clip_image006
  4. Site collection deleted.
    clip_image008

PowerShell To Add Secondary Site Collection Admin

Situation: You want to add secondary site collection administrator

Old Method: Go to Central Admin… or use stsadm

Smart Method: Use PowerShell

How?

Launch your Administrator: SharePoint 2010 Management Shell

Type

Set-SPSite –Identity http://server –SecondaryOwnerAlias justsharepoint\alpesh

 

image

This will add secondary site collection administrator. Soon will show you how you can add secondary site collection administrator for all site collections in a managed path!

PowerShell To Create a New Site Collection

Situation: You want to create a new site collection in your SharePoint environment

Old Method: Go to Central Admin…

Smart Method: Use PowerShell

How?

Launch your Administrator: SharePoint 2010 Management Shell

Type

New-SPSite –url http://server/sites/DocumentCenter -OwnerAlias justsharepoint\administrator -Name "Document Center” –Template BDR#0

image

This will create a site collection with Document Center Template.

PowerShell To Retrieve All Site Collections for Web Application

Situation: You want a list of all site collections in a Web Application of your SharePoint Farm

Old Method: Go to Central Admin …

Smart Method: Use PowerShell

How?

Launch your Administrator: SharePoint 2010 Management Shell

Type

get-spsite –webapplication http://server

 

alpesh.nakars.com

That’s it! Lists all your site collections in a web application.

PowerShell To Retrieve List of Web Application

Situation: You want to know how many web applications have been created in your SharePoint Farm.

Read the rest of this entry »

Scripts to backup and restore SharePoint 2007

I can add this to my arsenal of SharePoint Scripts. Just perfect.

FULL_BACKUP.BAT – Use Control Panel – Scheduler to run once a week. Don’t forget the ‘Run As’ account also needs write access to the backup location, in addition to the Central Admin app pool identity, and the SQL Server Machine account. This command will backup the entire farm to the following file share. Don’t use drive:\directory format.

–Start–

“c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm.exe” -o backup -directory \\servername\backupshare -backupmethod full

–end–

DIFF_BACKUP.BAT – Use Control Panel -Scheduler to run when you want differential backups. Remember the same security as above, but also it will fail if you add a content DB or Web App since the last FULL backup.

–start–

“c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm.exe” -o backup -directory \\servername\sharename -backupmethod differential

–end–

IIS_MetaBase_Backup.BAT – This is used to backup your IIS Configs to each IIS server, in their respective ‘metaback’ directories. Just add an additional line for each server you want to backup. It will create a backup of the metabase called ‘WeeklyBackup’ with a version appended. The password doesn’t matter, it just makes the backup portable.

–start–

cscript.exe %systemroot%\system32\iisback.vbs /s servername /u domain\username  /p userpassword /backup /b WeeklyBackup /v NEXT_VERSION /e password

cscript.exe %systemroot%\system32\iisback.vbs /s servername2 /u domain\username  /p userpassword /backup /b WeeklyBackup /v NEXT_VERSION /e password

cscript.exe %systemroot%\system32\iisback.vbs /s servername3 /u domain\username  /p userpassword /backup /b WeeklyBackup /v NEXT_VERSION /e password

–end–

As Ben says, use at your own risk.

Stay tuned, subscribe via email

Unattended SQL Server 2005 Installation

This is Part 2 of the 100% Scripted MOSS Installation. In Part 1 of the series, MOSS was installed on SQL SERVER 2005 Express edition. In this series, we will install SQL SERVER 2005 Enterprise Edition using a script, followed with a recap of installation of MOSS and then configuring MOSS using scripts. This will be a shorter journey, since we have seen various permutations in the earlier series.

I have used the instructions from MSDN to configure and install SQL Server 2005 Enterprise Edition.

start /wait C:\BUILD\Packages\MOSS\SQL2005\Servers\setup.exe /qb ADDLOCAL=Client_Components,Connectivity,SQL_Documentation,SQL_Tools90

start /wait C:\BUILD\Packages\MOSS\SQL2005\Servers\setup.exe /qb INSTANCENAME=MOSS2007 ADDLOCAL=SQL_Engine SAPWD=password SQLACCOUNT=domain\sqlserviceaccount SQLPASSWORD=password AGTACCOUNT=domain\sqlserviceaccount AGTPASSWORD=password SQLBROWSERACCOUNT=domain\sqlserviceaccount SQLBROWSERPASSWORD=password SECURITYMODE=SQL

As in earlier series, application installation packages are in

C:\Build\Packages\MOSS\ and copy your SQL SERVER 2005 CD to

C:\Build\Packages\MOSS\SQL2005\

Then apply Service Packs

start /wait C:\BUILD\Packages\MOSS\SQLSERVER2005SP1-KB913090-x86-ENU.exe /allinstances /quiet

start /wait C:\BUILD\Packages\MOSS\SQLSERVER2005SP2-KB921896-x86-ENU.exe /allinstances /quiet

/allinstances /quiet applies service pack to all instances quietly

You can download the scripts from my sky drive

For further customized options you can refer to MSDN Article here.

Next recap of MOSS Installation.