Showing posts with label host named site collection. Show all posts
Showing posts with label host named site collection. Show all posts

Friday, June 26, 2015

Creating Host Name Site Collection via PowerShell

Updates

Note that you can use a wildcard entry as per this blog thx Todd

Microsoft now recommends using no host header
https://technet.microsoft.com/en-us/library/cc424952.aspx#section2a

CREATING HOST-NAMED SITE COLLECTIONS IN SHAREPOINT 2013

https://sergeluca.wordpress.com/2014/01/13/creating-host-named-site-collections-in-sharepoint-2013/

http://www.benjaminathawes.com/2013/12/11/using-host-named-site-collections-in-sharepoint-2013-with-mysites/

Quickly Migrate SharePoint Path-based to Host-named Site Collections Using Feb 2015 PU

http://thesharepointfarm.com/2015/02/quickly-migrate-sharepoint-path-based-host-named-site-collections/

NHSC Lab without Host Header

Note you will need to add the following for the above example powershell to work properly.

  1. Create managed account called … 'Contoso\JDoe'
  2. DNS CNAME Record for portal.contoso.com using ‘nyc-sp1’

image

Three lines of powershell from Technet

  1. New-SPWebApplication -Name 'Contoso Sites' `
    -port 80 -ApplicationPool ContosoAppPool `
    -ApplicationPoolAccount `
    (Get-SPManagedAccount 'Contoso\JDoe') `
    -AuthenticationProvider ~
    (New-SPAuthenticationProvider `
    -UseWindowsIntegratedAuthentication)
  2. New-SPSite 'http://nyc-sp1' -Name 'Portal' `
    -Description 'Portal on root' `
    -OwnerAlias 'contoso\administrator' `
    -language 1033 -Template 'STS#0'
  3. New-SPSite 'http://portal.contoso.com' `
    -HostHeaderWebApplication 'http://nyc-sp1' `
    -Name 'Portal' -Description 'Customer root' `
    -OwnerAlias 'contoso\administrator' `
    -language 1033 -Template 'STS#0'
image 
I don’t like the database name from Technet code so think about creating database with a better name!
add -databasename ContosoSites

NHSC Lab using Host Header

So the future for Microsoft is to use Host Named Site Collections and since we have no GUI, my challenge has been to script this via PowerShell.  But many examples on the web have come up short and since I have been real busy this project has been put on the back burner.  Finally!

For my students, I am using 20331 Lab 8 but you can use any SharePoint farm, but you will need to modify the IP address and domain names as needed.

Using 20331 Lab 7/8 verified

Prerequisite #1 - Create DNS Records

A Record
webapp.contoso.com – 172.16.1.22
CNAME Records
root.contoso.com - webapp.contoso.com
companyA.contoso.com - webapp.contoso.com
companyB.contoso.com - webapp.contoso.com

image_thumb[13]

Prerequisite #2 – Add 172.16.1.22 to NIC

image_thumb[12]

Prerequisite #3 – Edit BackConnectionHostNames

Using regedit navigation to

image_thumb[5]

add values for the all four sites added to DNS earlier.

image_thumb[7]

Prerequisite #4 – Here is the script

   1:  # Using 20331 lab 8 vm
   2:  # DNS and TCPIP prerequisites
   3:  # create A record for webapp.contoso.com `
to 172.16.1.22 and add 172.16.1.22 to NIC
   4:  # create cname records to webapp.contoso.com`
for webapp, root, companya, companyb
   5:  # add sites to backconnectionhostnames if`
needed
   6:   
   7:  # Load SharePoint PowerShell Snapin
   8:  Add-PSSnapin microsoft.sharepoint.powershell
   9:   
  10:  # Web Application Variables
  11:  $webapphostheadersimple = 'webapp.contoso.com'
  12:  $webapphostheader = 'http://webapp.contoso.com'
  13:  $webappname = 'Portal WebApp'
  14:  $language = '1033'
  15:  $ipaddress = '172.16.1.22'
  16:   
  17:  # Site Collection Variables
  18:  $RootSC = 'http://root.contoso.com'
  19:  $rootSCname = 'Root Site'
  20:  $HNSC1 = 'http://companyA.contoso.com'
  21:  $HNSC1name = 'Company A'
  22:  $HNSC2 = 'http://companyB.contoso.com'
  23:  $HNSC2name = 'Company B'
  24:   
  25:  $rootsitetemplate = 'STS#0'
  26:  $sitetemplate = 'BLANKINTERNET#0'
  27:  $webdb = 'wss_content_portal'
  28:   
  29:  # Account Variables
  30:  $owneralias = 'contoso\administrator'
  31:  $serviceaccount = 'contoso\spcontosocomapppool'
  32:   
  33:  # Create Authentication Provider
  34:  $ap = new-spauthenticationprovider -usewindowsintegratedauthentication
  35:   
  36:  # Create New Web Application
  37:  new-spwebapplication -name $webappname `
-hostheader $webapphostheadersimple -port 80 `
-applicationpool $webappname -applicationpoolaccount`
$serviceaccount -databasename $webdb `
-allowanonymousaccess -authenticationprovider $ap
  38:   
  39:  # Create IIS Binding
  40:  new-webbinding -name $webappname `
-hostheader "*" -ipaddress $ipaddress `
-port 80 -protocol http
  41:   
  42:  # Create root site collection
  43:  new-spsite $RootSC -hostheaderwebapplication`
$webapphostheader -name $rootSCname –description `
$rootSCname -owneralias $owneralias -language`
$language -template $rootsitetemplate
  44:   
  45:  # Create host named site collection for CompanyA
  46:  new-spsite $HNSC1 -hostheaderwebapplication`
$webapphostheader -name $HNSC1name -description`
$HNSC1name -owneralias $owneralias -language`
$language -template $sitetemplate
  47:   
  48:  # Create host named site collection for`
CompanyB
  49:  new-spsite $HNSC2 -hostheaderwebapplication`
$webapphostheader -name $HNSC2name -description`
$HNSC2name -owneralias $owneralias -language`
$language -template $sitetemplate

Results – Here are site collections and web application


image_thumb[16]

image_thumb[11]



image_thumb[15]


Option Step - If needed edit IIS bindings


Appears to work fine with unassigned binding for webapp.contoso.com


imageimage_thumb[9]

Multiple zones for host named site collections in SP2013

https://blogs.msdn.microsoft.com/brian_farnhill/2014/07/07/multiple-zones-for-host-named-site-collections-in-sp2013/

SharePoint 2010 HNSC

https://blogs.msdn.microsoft.com/kaevans/2012/03/27/what-every-sharepoint-admin-needs-to-know-about-host-named-site-collections/

Create Site Collections via PowerShell

2013

Renaming Site Collections

$site = Get-SPSite http://portal.contoso.com/sites/demo
$uri = New-Object System.Uri("http://demo.contoso.com")
$site.Rename($uri)

Thx Todd - How to Rename SharePoint 2013 Site Collections Without Prayer or Sobbing

Host Named Site Collections

So the future for Microsoft is to use Host Named Site Collections and since we have no GUI, my challenge has been to script this via PowerShell.  But many examples on the web have come up short and since I have been real busy this project has been put on the back burner.  Finally!

For my students, I am using 20331 Lab 8 but you can use any SharePoint farm, but you will need to modify the IP address and domain names as needed

http://thecloudengineer.blogspot.com/2014/09/creating-host-name-site-collection-via.html

2010 Archive

How do you create multiple site collections via PowerShell?

The following script allows you to create a site collection with a dedicated content db and url.

First you set an array with the site collection names, then add managed path, content db and site collections for each url in the array.

$a = ("Engineering", "Sales")
ForEach($url in $a)
{
New-SPManagedPath -relativeurl /$url -webapplication http://intranet.contoso.com -explicit

New-SPContentDatabase -Name WSS_Content_Intranet_$url -WebApplication http://intranet.contoso.com

New-SPSite -Url http://intranet.contoso.com/$url -ContentDatabase WSS_Content_Intranet_$url -OwnerAlias CONTOSO\SP_Admin -Template "STS#0"
}

Special Site Collections
 
Hosted Named Site Collections (great article)
http://blogs.msdn.com/b/kaevans/archive/2012/03/27/what-every-sharepoint-admin-needs-to-know-about-host-named-site-collections.aspx

http://blogs.msdn.com/b/markarend/archive/2012/05/30/host-named-site-collections-hnsc-for-sharepoint-2010-architects.aspx (scripts confirmed)

How to Create Host Named Site Collections (I found some good code samples and reposted below in case of site deletion) Note you need to add the DNS entries for both.

http://mshorrosh.blogspot.com/2014/02/quick-guide-to-implementing-host-name.html

   1:  #"Add SharePoint Cmdlets"
   2:  add-pssnapin microsoft.sharepoint.powershell
   3:   
   4:  # Web App Variables
   5:  $WebAppDefault = "SharePoint - HSNC Example"
   6:  $Port = "80"
   7:  $AppPool = "HSNCAppPool"
   8:  $Account = "domain\svc-apppoolaccount"
   9:   
  10:  # Root Site Variables'
  11:  $RootHHDefault = "myrootsite.com"
  12:  $RootURLDefault = "http://myrootsite.com"
  13:  $Owner = "domain\svc-farmaccount"
  14:  $RootDB = "RootDB"
  15:  $Lang = "1033"
  16:  $Template = "blankinternetcontainer#0"
  17:   
  18:  # HSNC Site Variables
  19:  $HNSCSITE1 = "http://hnsc1.com"
  20:  $HNSCSITE2 = "http://hnsc2.com"
  21:   
  22:  # Create Web App
  23:  New-SPWebApplication -Name $WebAppDefault -hostHeader $RootHHDefault -Port $port -ApplicationPool $AppPool -ApplicationPoolAccount (Get-SPManagedAccount $Account) -AuthenticationProvider (New-SPAuthenticationProvider –UseWindowsIntegratedAuthentication) -DatabaseName $RootDB -AllowAnonymousAccess
  24:  echo "Web App created"
  25:   
  26:  # Create Root Site Collection 
  27:  New-SPSite $RootURLDefault -Name 'Root Site' -Description 'External Root Site Collection' -OwnerAlias $Owner -language $Lang -Template $Template
  28:  echo "Root Site Collection created"
  29:   
  30:  # Create HNSC 1
  31:  New-SPSite $HNSCSITE1 -HostHeaderWebApplication (get-spwebapplication $RootURLDefault) -Name 'Site 1' -Description 'HNSC Site1' -OwnerAlias $Owner -language $Lang -Template $template
  32:  echo "HNSC 1 Site Collection created"
  33:   
  34:  # Create HNSC 2
  35:  New-SPSite $HNSCSITE2 -HostHeaderWebApplication (get-spwebapplication $RootURLDefault) -Name 'Site 2' -Description 'HNSC Site2' -OwnerAlias $Owner -language $Lang -Template $template
  36:  echo "HNSC 2 Site Collection created"






http://www.sharepointdiary.com/2014/06/create-host-named-site-collections-in-sharepoint-2013.html



image



   1:  Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
   2:  #Set variables for New web application creation
   3:  $WebAppName = "HNSC Host Web Application"
   4:  #Variables for new Application Pool
   5:  $AppPoolName = "HNSC App Pool"
   6:  #Get the existing Managed Account
   7:  $AppPoolAccount = Get-SPManagedAccount "Crescent\SvcAppPool"
   8:  #To utilize existing AppPool, Use: Get-SPServiceApplicationPool <AppPoolName>
   9:  $ContentDatabase = "SP13_HNSC_Content"
  10:  $AuthProvider = New-SPAuthenticationProvider –UseWindowsIntegratedAuthentication
  11:  #Create the web application
  12:  $WebApp = New-SPWebApplication -ApplicationPool $AppPoolName -ApplicationPoolAccount $AppPoolAccount 
 

 

   1:  $ServerName = "http://G1WFE01"
   2:  New-SPSite -URL $ServerName -Name "HNSC Root" -OwnerAlias "Global\SvcOwner"
 






   1:  $HostURL = "http://WFE01"
   2:  $OwnerID = "Crescent\Support"
   3:  $OwnerMail= "Support@Crescent.com"
   4:  $SiteURL = "http://sales.crescent.com"
   5:  $TemplateVal ="sts#0" #Team Site
   6:  #Create the HNSC
   7:  New-SPSite -url $SiteURL -HostHeaderWebApplication $HostURL -owneralias $OwnerID -owneremail $OwnerMail -Template $TemplateVal










 
Unlike SharePoint 2010, SharePoint 2013 allows managed paths in host named site collections. Here is how: Create a new managed path "teams"


 










   1:  New-SPManagedPath "Teams" –Hostheader

 

 

 

   1:  $HostURL = "http://WFE01"
   2:  $OwnerID = "Crescent\Salaudeen"
   3:  $OwnerMail= "Support@Crescent.com"
   4:  $SiteURL = "http://Sales.crescent.com/teams/cloud"
   5:  $SiteName = "Clould Sales Team"
   6:  $TemplateVal ="sts#0"
   7:  #Get the Host named site collection by its name
   8:  $webApp = Get-SPWebApplication $HostURL
   9:  #Create new Host-named site under the managed path
  10:  New-SPSite $SiteURL -OwnerAlias $OwnerID -HostHeaderWebApplication $webApp -Name $SiteName -Template $TemplateVal