Tuesday, November 27, 2012

How to Create a Site using PowerShell Script


Write-Host
# define variables for script
$SiteTitle = "Lab 1 - Getting Started"
$SiteUrl = "http://ServerName:1234/sites/HR"
$SiteTemplate = "STS#1"
# check to ensure Microsoft.SharePoint.PowerShell is loaded
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

# delete any existing site found at target URL
$targetUrl = Get-SPSite | Where-Object {$_.Url -eq $SiteUrl}
if ($targetUrl -ne $null) {
  Write-Host "Deleting existing site at" $SiteUrl
  Remove-SPSite -Identity $SiteUrl -Confirm:$false
}

# create new site at target URL
Write-Host "Creating new site at" $SiteUrl
$NewSite = New-SPSite -URL $SiteUrl -OwnerAlias Administrator -Template $SiteTemplate -Name $SiteTitle
$RootWeb = $NewSite.RootWeb

# display site info
Write-Host
Write-Host "Site created successfully" -foregroundcolor Green
Write-Host "-------------------------------------" -foregroundcolor Green
Write-Host "URL:" $RootWeb.Url -foregroundcolor Yellow
Write-Host "ID:" $RootWeb.Id.ToString() -foregroundcolor Yellow
Write-Host "Title:" $RootWeb.Title -foregroundcolor Yellow
Write-Host "-------------------------------------" -foregroundcolor Green





2 comments:

  1. 7D53F20C4F
    When considering options for customizing apparel, many people turn to innovative techniques like dtf transfers for vibrant and durable designs. These transfers allow for high-quality images to be applied seamlessly onto fabrics, making them a popular choice among small business owners and hobbyists alike. The process is relatively straightforward, providing a cost-effective way to produce detailed and colorful prints. If you're looking to elevate your custom clothing game, exploring dtf transfers could be a game-changer for your projects.

    ReplyDelete

Featured Post

Create SharePoint Folder Structure in Destination (Only If Not Exists)

Why This Script Is Safe You can run it multiple times It will not create duplicate folders It will only create missing folders S...

Popular posts