Sunday, December 1, 2013

Install SharePoint 2010

שלום חברים,
אפרט מניסיוני על התקנת חווה של SharePoint 2010 . חוות ה-SharePoint שהתקנתי מורכבת מ-2 שרתים, האחד FE  והשני DB.
השרתים עליהם התקנתי את ה-SharePoint היו שרתי Windows Server 2008R2, וה-SQL היה בגרסת SQL Server 2008R2.


טיפ: הורידו את כל העדכונים האחרונים לשרת לפני שאתם מתחילים את ההתקנה, גם עדכונים של מערכת ההפעלה (Windows Update) וגם עדכונים של Microsoft (Microsoft Updates, עדכונים למוצרי Microsoft שמותקנים בשרת). בצעו את העדכונים עד שלא יופיעו עדכונים בחלון. ) תידרשו לבצע מספר אתחולים, תלוי במספר העדכונים שהשרת צריך לבצע)


החווה מורכבת מ-2 שרתים וירטואלים כך שה-FE  היה עם 8GB  - RAM, 4 ליבות ו-80GB לדיסק מערכת ההפעלה, בנוסף שרת DB  עם 16 GB  - RAM, 8 ליבות  ו-80GB לדיסק מערכת ההפעלה ועוד 200 GB דיסק Data ו-60GB ל-Logs.

הגדרתי -3 Users לחווה:

SPAdmin:
ההרשאות שנדרש לקבל:
1.       חבר בקבוצת מנהלי המערכת בכל שרת שבו התקנה פועלת. (Administrators)





2.       חבר בתפקידים הבאים של SQL Server : (Server roles)
a.       Securityadmin
b.       Dbcreator
c.       אם אתם מפעילים רכיבי cmdlet של Windows PowerShell המשפיעים על מסד נתונים, חשבון זה חייב להיות חבר בתפקיד הקבוע db_owner עבור מסד הנתונים.

SPservices:
ההרשאות שנדרש לקבל:
1.       חבר בתפקידים הבאים של SQL Server : (Server roles)
לאחר שתפעיל את אשף התצורה של  SharePoint(Configuration Wizard)
a.       Securityadmin
b.       Dbcreator
c.        db_owner עבור כל ה- DBים של SharePoint במסד הנתונים.

SPAppPool
מתחילים את ההתקנה של ה- prerequisite installer , לחץ Double Click  על הקובץ ולאחר מכן בחר "Yes".





לחץ על Next ולאחר מכן אשר את התנאים...






ההתקנה התחילה (במידה ואין לכם חיבור לאינטרנט יש להוריד את הרכיבים ברשימה ולהתקין אותם עצמאית ,ניתן להיעזר במאמר הזה). 





מומלץ לבדוק ששני ה-Roleים התווספו (IIS/App Server).



מיד לאחר מכן מפעילים את ההתקנה של SharePoint, לחיצה על הקובץ Setup פעמיים ונפתח חלון תפריט של ההתקנה.


חלון Enter your Product Key מוצג, הכנס את ה- Product Key ולחץ על "המשך". 




קבל את התנאים...  ולחץ על המשך. 



חלון Server Type מוצג , יש לבחור באופציה Complete ולאחר מכן לעבור ללשונית File Location כדי לבחור נתיב לקבציי ה-Index (במידה ומופעל שירות החיפוש).




 לחץ על "התקנה" וההתקנה מתחילה ...



 בסוף ההתקנה מופיע חלון Run Configuration Wizard , בחר שלא להריץ את ה- Configuration Wizard  ואל תסמן את תיבת הסימון,  לאחר מכן סגור את החלון.




יצירת Databases בעזרת PowerShell

בשלב זה ניצור Databases,
SharePoint Config Database בעזרת PowerShell : נעזרתי במאמר הזה
המוטיבציה ליצור SharePoint Config בעזרת PowerShell היא ערבוב של מס' Databases ב-SQL ריכוזי שיכול להכיל גם Databases של SharePoint2010 ו – SharePoint 2010 , ה- Databases שנוצרים בתהליך ההתקנה האוטומטי נוצרים עם Guidים מה שמקשה על זיהוי Databases, חוסר אסטטיקה ובעיות עם Databases שמוכל בהם התו " " (רווח).



להלן ה-Script :
#====================================
#====================================
#Provision Configuration and Administration Databases
#====================================
#====================================

Add-PSSnapin Microsoft.SharePoint.PowerShell

#This is the name of your SQL Alias
#----------------------------------------------
$AliasName = "Write Here The Alias Name if you Use Alias"
<#If you don't use Alias, You Cane Delete this Command#>

# Farm configuration
#----------------------------------------------
$configDbName = "SharePointConfig2010"
$AdminContentDB = "SharePointAdminContent2010"
$DBServer = "Server Name" # Change the Text between the quotation 
$FarmAccount = "Domain\UserName" # Change the Text between the quotation
$FarmCredential = Get-Credential -credential $FarmAccount

Write-Warning "Enter Passphrase"
$Passphrase = ConvertTo-SecureString "SharePoint2010!" -AsPlainText -Force

# Create SharePoint Config DataBase
#------------------------------------------------
Write-Host "Creating new configuration database..." -foregroundcolor Cyan
New-SPConfigurationDatabase -DatabaseName $configDbName -DatabaseServer $DBServer -AdministrationContentDatabaseName $AdminContentDB -Passphrase $Passphrase -FarmCredentials $FarmCredential

Write-Host "SharePoint Configuration Database was create Successfully ! " -foregroundcolor Green

גש לשרת ה-SQL ובדוק שה- Databasesאכן נוצרו, הפלא ופלא הם אכן נוצרו כמו שצריך !




בשלב הבא מריצים את ה- Configuration Wizard  , החלון מופיע, לחץ על Next



 החלון מתריע על Serviceים שהתחילו או יאותחלו, לחץ על "Yes



מופיע חלון  Modify server farm Settings , רשום  את שם ה-DB ובחר ב-SharePoint Config שהתקנת מקודם בעזרת ה-PowerShell. בחר באופציה "Don't Disconnect from this server farm"  ולחץ Next. 
  




החלון Configure SharePoint Central Administration Web Application מופיע , שנה את ה-Port ל- 50000 ובחר ב-NTLM , 






לחיצה על Next תוביל לחלון Completing the SharePoint Products Configuration Wizard בו מוצגים כל ההגדרות הרלוונטיות, 



לחיצה על Next וה- Configuration Wizard מתחיל לרוץ.




במידה והכול הולך קשורה החלון הבא יופיע בסיום הריצה Configuration Successfulלחץ  על Finish ומיד לאחר מכן ה- Central Admin נטען.







הדף Help Make SharePoint Better מופיע, בחר ב-No ולחץ על OK. דף Welcome מוצג בחר ב-Cancel ולאחר מכן מופיע-Central Admin.
בגדול ההתקנה הסתיימה, במידה ותרצו להמשיך להתקין Service Application ניתן לעשות זאת דרך ה-Central Admin או בעזרת PowerShell.
יש להתקין את ה-Service Application הבאים : (אני בחרתי בדרך השנייה - PowerShell)


The State Service is a shared service that is used by some Microsoft SharePoint Server 2010 components to store temporary data across related HTTP requests in a SQL Server database


#====================================
 #====================================
 #Provision State Service Application
 #====================================
 #====================================

 #Create and Initialoze the State Service Database
 #----------------------------------------------------------------

 Write-host "Step 1 : Create and Initialoze the State Service Database " -foregroundcolor Cyan
 $dbServer = "Server Name" # Change the Text between the quotation, if you Use Alias Method Write the Alias Name
 $dbName = "State_Service_DB"
 $db = Get-SPStateServiceDatabase $dbName
 if($db -eq $null)
 {
   $db = New-SPStateServiceDatabase -Name $dbName -DatabaseServer $dbServer -Weight 1
   $db | Initialize-SPStateServiceDatabase
 }
 else
 {
 Write-host "There is a Database with the same name .. please change the name !" -foregroundcolor Red
 }


 #Create the Service Application
 #----------------------------------------------------------------

 Write-host "Step 2 : Create the Service Application " -foregroundcolor Cyan
 $appName = "State Services Service Application"
 $app = Get-SPStateServiceApplication $appName
 if($app -eq $null)
 {
 $app = New-SPStateServiceApplication -Name $appName -Database $db
 }
 else
 {
 Write-host "There is a Service Application with the same name .. please change the name !" -foregroundcolor Red
 }


 #Create the Service Application Proxy
 #----------------------------------------------------------------

 Write-host "Step 2 : Create the Service Application Proxy " -foregroundcolor Cyan
 $proxyName = "$($app.Name) Proxy"
 $proxy = New-SPStateServiceApplicationProxy -ServiceApplication $app -Name $proxyName -DefaultProxyGroup






#====================================
#====================================
#Provision Search Service Application
#====================================
#====================================


#set the name for the Service Application
#----------------------------------------------------------
$serviceAppName = "Search Service Application"


#Set the server names for core pieces
#------------------------------------------------------
$serverName = "Server Name"         #Admin/Index
$queryserverName = "Server Name"      #Query
$dbserverName = "Server Name"          #DB

<# if you are install all the component on one server just the server name and delete the other from the script,
don't forget to chanage the server names in the script below #>


#IndexLocation
#-----------------------------
$IndexLocation = "F:\Data\Search14Index” #Location must be empty, will be deleted during the process! 
mkdir -Path $IndexLocation -Force

#Search component
#-----------------------------
$adminServer = $serverName   #recommended that the component be locate alongside a Crawl Component
$crawlServer = $serverName
$queryServer = $queryserverName
$dbServer = $dbserverName      #Change the value if you have Seperate SQL Server
$searchDBName = "SearchServiceApplication"

#Define Service Account / ApplicationPool Account
#--------------------------------------------------------------------------
Write-Host "Step 1 : Define Service Account" -foregroundcolor Cyan
$searchCred = "Domain\UserAccount"    #Repalce The Text With Real Account
$cred = Get-Credential $searchCred
$searchSvcAccount = Get-SPManagedAccount $cred.UserName -ErrorAction SilentlyContinue

if($searchSvcAccount -eq $null)
{
     $searchSvcAccount = New-SPManagedAccount $cred
}


Write-Host "Step 2 : Define Application Pool Account" -foregroundcolor Cyan
$AppPoolsearchCred = "Domain\UserAccount"   #Repalce The Text With Real Account
$cred = Get-Credential $AppPoolsearchCred
$searchAppPoolAccount = Get-SPManagedAccount $cred.UserName -ErrorAction SilentlyContinue

if($searchAppPoolAccount -eq $null)
{
     $searchAppPoolAccount = New-SPManagedAccount $cred
}


<#One additional account that you will need is the default content access account.
  this account should not be a managed account and therefore requires no additional congiuration steps #>


#Get Search Service Instance if exist
#-----------------------------------------
Write-Host "Step 3 : Get Search Service Instance if exist" -foregroundcolor Cyan
$searchSvc = Get-SPEnterpriseSearchServiceInstance -Local
if($searchSvc -eq $null)
{
  throw "Unable to Retrive Search Service"
}


#Start the search service
#-----------------------------------------
Write-Host "Step 4 : Start the search service" -foregroundcolor Cyan
if($searchSvc.Status -ne "Online")
{
  $searchSvc | Start-SPServiceInstance
  Write-Host "the search service is  now Online" -Foregroundcolor Green
}
else
{
  Write-Host "the search service is already Online" -Foregroundcolor Yellow
}



#Configure the search Service
#-----------------------------------------
Write-Host "Step 5 : Configure the search Service" -foregroundcolor Cyan
$contactEmail = "mailAdress@SharePoint.com"
$connectionTimeOut = "60"
$acknowledgementTimeOut = "60"
$proxyType = "Default"
$ignoreSSLWranings = $false
$internetID = $null
$performanceLevel = "PartlyReduced"

Write-Host "Step 6 : Setting search service properties..." -foregroundcolor Yellow

while($true)
{
 $svc = Get-SPEnterpriseSearchService
 $svc | Set-SPEnterpriseSearchService -ServiceAccount $searchSvcManagedAccount.UserName -ServicePassword $searchSvcAccount.Password -ContactEmail $contactEmail -connectionTimeOut $connectionTimeOut -acknowledgementTimeOut $acknowledgementTimeOut -proxyType $proxyType -ignoreSSLWarnings $ignoreSSLWranings -internetIdentity $internetID -performanceLevel $performanceLevel -ErrorAction SilentlyContinue -ErrorVariable err
 if($err)
 {
   if($err[0].Exception.Message -like "*update conflict")
    {
  Write-Warning "An Update conflict occured"
  Start-Sleep 2
  continue
    }
  
    throw $err
 }

 break
}


Write-Host " Configure search service ended " -foregroundcolor Green



#Create Search Service Application
#--------------------------------------------------
Write-Host "Step 7 : Create $serviceAppName " -foregroundcolor Cyan

$searchApp = Get-SPEnterpriseSearchServiceApplication $serviceAppName -ErrorAction SilentlyContinue

$poolName = "Search Service Application Pool"
$AdminPoolName = "Search Service Application Admin Pool"

$saAppPool = New-SPServiceApplicationPool -Name $poolName -Account $searchAppPoolAccount
$saAdminAppPool = New-SPServiceApplicationPool -Name $AdminPoolName -Account $searchAppPoolAccount

Write-Host "Creating Search Service Application Now... " -foregroundcolor yellow
$searchApp = New-SPEnterpriseSearchServiceApplication -Name $serviceAppName -ApplicationPool $saAppPool -AdminApplicationPool $saAdminAppPool -DataBaseServer $dbServer -DataBaseName $searchDBName

Write-Host "Please wait while the Search Service Application are Creating... " -foregroundcolor yellow
Start-Sleep -s 30

if($searchApp -ne $null)
{
  Write-Host "Search Service Application Created Successfully ! " -foregroundcolor Green
}
else
{
  Write-Host "Search Service Application dosen't Created Successfully ! " -foregroundcolor Red
}


#Create the Service Application Proxy
#-----------------------------------------
Write-Host "Step 7 : Create the Service Application Proxy" -foregroundcolor Cyan

$searchProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$serviceAppName Proxy" -SearchApplication $searchApp

Write-Host "Please wait while the Search Service Application are Creating... " -foregroundcolor yellow
Start-Sleep -s 10

if($searchProxy -ne $null)
{
  Write-Host "Search Service Application Proxy Created Successfully ! " -foregroundcolor Green
}
else
{
  Write-Host "Search Service Application Proxy dosen't Created Successfully ! " -foregroundcolor Red
}



#Configure the Administration Component
#-----------------------------------------------------
Write-Host "Step 9 : Configure the Administration Component" -foregroundcolor Cyan

$adminSearchInstance = Get-SPEnterpriseSearchServiceInstance $adminServer

if($adminSearchInstance.Status -ne "Online")
{
  $adminSearchInstance | Start-SPServiceInstance
}
else
{
write-host "Admin Search Instance is Online" -foregroundcolor Green
}


$admin = ($searchApp | Get-SPEnterpriseSearchAdministrationComponent)
$admin | Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $adminSearchInstance
$admin = ($searchApp | Get-SPEnterpriseSearchAdministrationComponent)
while(-not $admin.Initialized)
{
Start-Sleep 10
$admin = ($searchApp | Get-SPEnterpriseSearchAdministrationComponent)
}

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $adminServer


Write-Host " Configure Administration Component ended " -foregroundcolor Green

Start-Sleep -s 5


#Create the Crawl and Query Components
#-------------------------------------------------------
Write-Host "Step 10 : Create the Crawl and Query Components" -foregroundcolor Cyan
$initialCrawlTopology = ($searchApp | Get-SPEnterpriseSearchCrawlTopology)
$initialQueryTopology = ($searchApp | Get-SPEnterpriseSearchQueryTopology)

#Crawl
#-------
Write-Host "=== Crawl Component ===" -foregroundcolor Cyan
$crawlTopology = ($searchApp | New-SPEnterpriseSearchCrawlTopology)
$crawlDB = Get-SPEnterpriseSearchCrawlDatabase -SearchApplication $searchApp
$crawlInstance = Get-SPEnterpriseSearchServiceInstance $crawlServer


$crawlComponent = New-SPEnterpriseSearchCrawlComponent -CrawlTopology $crawlTopology -CrawlDatabase $crawlDB -SearchServiceInstance $crawlInstance

$crawlTopology | Set-SPEnterpriseSearchCrawlTopology -Active
do
{
 Start-Sleep 5
 $crawlTopology = $searchApp | Get-SPEnterpriseSearchCrawlTopology $crawlTopology
}
while($crawlTopology.State -ne "Active")

Write-Host " Configure Crawl Component ended " -foregroundcolor Green

<# It is important to wait until the process of Crawl initiation will be finished
   After it done you can initiate the query Component #>

#Query
#--------
Write-Host "=== Query Component ===" -foregroundcolor Cyan
Start-Sleep -s 300
$queryTopology = ($searchApp | New-SPEnterpriseSearchQueryTopology -Partitions 1 )
$propDB = Get-SPEnterpriseSearchPropertyDatabase -SearchApplication $searchApp
$indexPartition = Get-SPEnterpriseSearchIndexPartition -QueryTopology $queryTopology
$indexPartition | Set-SPEnterpriseSearchIndexPartition -PropertyDatabase $propDB


$svc = Get-SPEnterpriseSearchServiceInstance $queryServer
$queryComponent = New-SPEnterpriseSearchQueryComponent -queryTopology $queryTopology -indexPartition $indexPartition -SearchServiceInstance $svc


$queryTopology | Set-SPEnterpriseSearchqueryTopology -Active
do
{
 Start-Sleep 5
 $queryTopology = $searchApp | Get-SPEnterpriseSearchqueryTopology $queryTopology
}
while($queryTopology.State -ne "Active")

Write-Host " Configure Query Component ended " -foregroundcolor Green
$initialCrawlTopology | Remove-SPEnterpriseSearchCrawlTopology -confirm:$false


# Activate the Topology
#-------------------------------
if($initialQueryTopology.State -eq "Deactivating")
{
 Write-Host "Wait for Deactivating the Query Component" -foregroundcolor Yellow
  do
  {

  }
  while($initialQueryTopology.State -eq "Deactivating")
}
else
{
  Start-Sleep -s 120
  $initialQueryTopology | Remove-SPEnterpriseSearchQueryTopology -confirm:$false
}


Write-Host " ======== The End ========" -foregroundcolor Green

ניתן לבדוק שה-Service Application התווסף דרך ממשק ה-Central Admin , כנס ל- Central Administration בחר ב- Application Management ולאחר מכן בManage service applications אתה אמור לראות את הService Application  שיצרת ברשימה.



אפשר להמשיך וליצור WebApplication דרך ה-Central Admin רק תקפיד בזמן היצירה לתת שם אינטואיטיבי ל-DB של ה-WebApplication.

בהצלחה !
רון נס.


============================================================================================================================================================================================================================================================

Hello Friends,

Today I will talk about my experience on installing SharePoint 2010 farm. The SharePoint I installed consists of 2 servers, one FE and the other DB.
The Servers that I installed were with Windows Server 2008R2, and SQL was SQL Server version 2008R2.

Tip: Download the latest Windows Update and microsoft updates before you start the installation. Do the updates until updates will not appear in the window. you Will be required to reboot, depending on the number of updates that the server should perform.

The farm consisted of 2 virtual servers so that the FE was with 8GB - RAM, 4 cores and 80GB operating system disk, in addition to DB server with 16 GB - RAM, 8 cores and 80GB operating system disk and 200 GB Data Disk and -60GB to Logs.

3 Users defined:
SPAdmin:
Permissions required:
1. Member of the Administrators group on each server where the installation operates. (Administrators)








2. A member of the following roles in SQL Server: (Server roles)
a. Securityadmin
b. Dbcreator
c. If you run cmdlets Windows PowerShell affect a database, this account must be a member of the db_owner fixed role for the database.

SPservices:
Permissions required:
1. A member of the following roles in SQL Server: (Server roles)
After you run the SharePoint Configuration Wizard (Configuration Wizard)
a. Securityadmin
b. Dbcreator
c. db_owner for all the children of the SharePoint DB database.


SPAppPool

I started the installation of the prerequisiteinstaller, pressed Double Click on the file and then clicked "Yes".





Clicked Next and then confirmed the conditions ... 



Installation started (if you have no Internet connection to download the components list and install them independently, you can use this article).







The process was very quick and the installation is complete.







 Recommended to check that both the added s Role (IIS / App Server).



Immediately after I activated the SharePoint installation, I clicked on the setup file twice and it opened a window installation menu. I clicked Install SharePoint Server and Window's User Account Control jumped, I clicked "Yes".









The Window Enter your Product Key is displayed, I put the Product Key and clicked "Continue". 




I got the conditions ... And clicked Continue. The Window Server Type was introduced and I opted Complete, and then I moved to the File Location tab to select the file path reservation (when powered search service). 




Clicking on "Install" and the installation begins ... At the end of the installation The window that appears was Run Configuration Wizard I chose not to run the Configuration Wizard and I marked the checkbox, then closed the window.










I created a SharePoint Config Database with PowerShell: I used this article
The Motivation to create "SharePoint Config" with PowerShell is a mixture Numbers of Databases, SQL concentrations can also contain Databases of ​​SharePoint2010 and SharePoint 2013, the Databases that are created during the installation process auto-created with Guides making it difficult to identify, lack of aesthetics and problems with DB is contained in character "" (space).
The following script:

#====================================
#====================================
#Provision Configuration and Administration Databases
#====================================
#====================================

Add-PSSnapin Microsoft.SharePoint.PowerShell

#This is the name of your SQL Alias
#----------------------------------------------
$AliasName = "Write Here The Alias Name if you Use Alias"
<#If you don't use Alias, You Cane Delete this Command#>

# Farm configuration
#----------------------------------------------
$configDbName = "SharePointConfig2010"
$AdminContentDB = "SharePointAdminContent2010"
$DBServer = "Server Name" # Change the Text between the quotation 
$FarmAccount = "Domain\UserName" # Change the Text between the quotation
$FarmCredential = Get-Credential -credential $FarmAccount

Write-Warning "Enter Passphrase"
$Passphrase = ConvertTo-SecureString "SharePoint2010!" -AsPlainText -Force

# Create SharePoint Config DataBase
#------------------------------------------------
Write-Host "Creating new configuration database..." -foregroundcolor Cyan
New-SPConfigurationDatabase -DatabaseName $configDbName -DatabaseServer $DBServer -AdministrationContentDatabaseName $AdminContentDB -Passphrase $Passphrase -FarmCredentials $FarmCredential

Write-Host "SharePoint Configuration Database was create Successfully ! " -foregroundcolor Green




I went to the SQL server and checked that the DBs actually created and lo and behold they actually were!



Next I ran the Configuration Wizard, the window appeared and press Next



, the window warns the Services started or boots appeared and I clicked on "Yes"




 window appears Modify server farm Settings I wrote the name of the DB and chose the name of SharePoint Config I installed before using the PowerShell. I chose the option "Do not disconnect from this server farm" and clicked Next.




The window Configure SharePoint Central Administration Web Application appears, I type in the Port field 50000 and I chose NTLM, click Next 




led me to the window Completing the SharePoint Products Configuration Wizard showing all relevant settings, clicking Next and - Configuration Wizard from running.







If all goes well, the following window will appear Configuration Successful, I clicked Finish and immediately after this Central Admin uploaded.










The Page Help Make SharePoint Better listed, I chose No in and clicked OK. The Welcome page is displayed on and I chose Cancel and then the Central Admin appeared.
The installation is complete, if you want to continue and install Service Application it can be done through the Central Admin or using PowerShell.
Install the following Application Service: (I chose the second way - PowerShell)

State Service Application:
THE STATE SERVICE IS A SHARED SERVICE THAT IS USED BY SOME MICROSOFT SHAREPOINT SERVER 2010 COMPONENTS TO TEMPORARY STORE RELATED DATA ACROSS HTTP REQUESTS IN A SQL SERVER DATABASE

#====================================
 #====================================
 #Provision State Service Application
 #====================================
 #====================================

 #Create and Initialoze the State Service Database
 #----------------------------------------------------------------

 Write-host "Step 1 : Create and Initialoze the State Service Database " -foregroundcolor Cyan
 $dbServer = "Server Name" # Change the Text between the quotation, if you Use Alias Method Write the Alias Name
 $dbName = "State_Service_DB"
 $db = Get-SPStateServiceDatabase $dbName
 if($db -eq $null)
 {
   $db = New-SPStateServiceDatabase -Name $dbName -DatabaseServer $dbServer -Weight 1
   $db | Initialize-SPStateServiceDatabase
 }
 else
 {
 Write-host "There is a Database with the same name .. please change the name !" -foregroundcolor Red
 }


 #Create the Service Application
 #----------------------------------------------------------------

 Write-host "Step 2 : Create the Service Application " -foregroundcolor Cyan
 $appName = "State Services Service Application"
 $app = Get-SPStateServiceApplication $appName
 if($app -eq $null)
 {
 $app = New-SPStateServiceApplication -Name $appName -Database $db
 }
 else
 {
 Write-host "There is a Service Application with the same name .. please change the name !" -foregroundcolor Red
 }


 #Create the Service Application Proxy
 #----------------------------------------------------------------

 Write-host "Step 2 : Create the Service Application Proxy " -foregroundcolor Cyan
 $proxyName = "$($app.Name) Proxy"
 $proxy = New-SPStateServiceApplicationProxy -ServiceApplication $app -Name $proxyName -DefaultProxyGroup






Search Service Application : 


#====================================
#====================================
#Provision Search Service Application
#====================================
#====================================


#set the name for the Service Application
#----------------------------------------------------------
$serviceAppName = "Search Service Application"


#Set the server names for core pieces
#------------------------------------------------------
$serverName = "Server Name"         #Admin/Index
$queryserverName = "Server Name"      #Query
$dbserverName = "Server Name"          #DB

<# if you are install all the component on one server just the server name and delete the other from the script,
don't forget to chanage the server names in the script below #>


#IndexLocation
#-----------------------------
$IndexLocation = "F:\Data\Search14Index” #Location must be empty, will be deleted during the process! 
mkdir -Path $IndexLocation -Force

#Search component
#-----------------------------
$adminServer = $serverName   #recommended that the component be locate alongside a Crawl Component
$crawlServer = $serverName
$queryServer = $queryserverName
$dbServer = $dbserverName      #Change the value if you have Seperate SQL Server
$searchDBName = "SearchServiceApplication"

#Define Service Account / ApplicationPool Account
#--------------------------------------------------------------------------
Write-Host "Step 1 : Define Service Account" -foregroundcolor Cyan
$searchCred = "Domain\UserAccount"    #Repalce The Text With Real Account
$cred = Get-Credential $searchCred
$searchSvcAccount = Get-SPManagedAccount $cred.UserName -ErrorAction SilentlyContinue

if($searchSvcAccount -eq $null)
{
     $searchSvcAccount = New-SPManagedAccount $cred
}


Write-Host "Step 2 : Define Application Pool Account" -foregroundcolor Cyan
$AppPoolsearchCred = "Domain\UserAccount"   #Repalce The Text With Real Account
$cred = Get-Credential $AppPoolsearchCred
$searchAppPoolAccount = Get-SPManagedAccount $cred.UserName -ErrorAction SilentlyContinue

if($searchAppPoolAccount -eq $null)
{
     $searchAppPoolAccount = New-SPManagedAccount $cred
}


<#One additional account that you will need is the default content access account.
  this account should not be a managed account and therefore requires no additional congiuration steps #>


#Get Search Service Instance if exist
#-----------------------------------------
Write-Host "Step 3 : Get Search Service Instance if exist" -foregroundcolor Cyan
$searchSvc = Get-SPEnterpriseSearchServiceInstance -Local
if($searchSvc -eq $null)
{
  throw "Unable to Retrive Search Service"
}


#Start the search service
#-----------------------------------------
Write-Host "Step 4 : Start the search service" -foregroundcolor Cyan
if($searchSvc.Status -ne "Online")
{
  $searchSvc | Start-SPServiceInstance
  Write-Host "the search service is  now Online" -Foregroundcolor Green
}
else
{
  Write-Host "the search service is already Online" -Foregroundcolor Yellow
}



#Configure the search Service
#-----------------------------------------
Write-Host "Step 5 : Configure the search Service" -foregroundcolor Cyan
$contactEmail = "mailAdress@SharePoint.com"
$connectionTimeOut = "60"
$acknowledgementTimeOut = "60"
$proxyType = "Default"
$ignoreSSLWranings = $false
$internetID = $null
$performanceLevel = "PartlyReduced"

Write-Host "Step 6 : Setting search service properties..." -foregroundcolor Yellow

while($true)
{
 $svc = Get-SPEnterpriseSearchService
 $svc | Set-SPEnterpriseSearchService -ServiceAccount $searchSvcManagedAccount.UserName -ServicePassword $searchSvcAccount.Password -ContactEmail $contactEmail -connectionTimeOut $connectionTimeOut -acknowledgementTimeOut $acknowledgementTimeOut -proxyType $proxyType -ignoreSSLWarnings $ignoreSSLWranings -internetIdentity $internetID -performanceLevel $performanceLevel -ErrorAction SilentlyContinue -ErrorVariable err
 if($err)
 {
   if($err[0].Exception.Message -like "*update conflict")
    {
  Write-Warning "An Update conflict occured"
  Start-Sleep 2
  continue
    }
  
    throw $err
 }

 break
}


Write-Host " Configure search service ended " -foregroundcolor Green



#Create Search Service Application
#--------------------------------------------------
Write-Host "Step 7 : Create $serviceAppName " -foregroundcolor Cyan

$searchApp = Get-SPEnterpriseSearchServiceApplication $serviceAppName -ErrorAction SilentlyContinue

$poolName = "Search Service Application Pool"
$AdminPoolName = "Search Service Application Admin Pool"

$saAppPool = New-SPServiceApplicationPool -Name $poolName -Account $searchAppPoolAccount
$saAdminAppPool = New-SPServiceApplicationPool -Name $AdminPoolName -Account $searchAppPoolAccount

Write-Host "Creating Search Service Application Now... " -foregroundcolor yellow
$searchApp = New-SPEnterpriseSearchServiceApplication -Name $serviceAppName -ApplicationPool $saAppPool -AdminApplicationPool $saAdminAppPool -DataBaseServer $dbServer -DataBaseName $searchDBName

Write-Host "Please wait while the Search Service Application are Creating... " -foregroundcolor yellow
Start-Sleep -s 30

if($searchApp -ne $null)
{
  Write-Host "Search Service Application Created Successfully ! " -foregroundcolor Green
}
else
{
  Write-Host "Search Service Application dosen't Created Successfully ! " -foregroundcolor Red
}


#Create the Service Application Proxy
#-----------------------------------------
Write-Host "Step 7 : Create the Service Application Proxy" -foregroundcolor Cyan

$searchProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$serviceAppName Proxy" -SearchApplication $searchApp

Write-Host "Please wait while the Search Service Application are Creating... " -foregroundcolor yellow
Start-Sleep -s 10

if($searchProxy -ne $null)
{
  Write-Host "Search Service Application Proxy Created Successfully ! " -foregroundcolor Green
}
else
{
  Write-Host "Search Service Application Proxy dosen't Created Successfully ! " -foregroundcolor Red
}



#Configure the Administration Component
#-----------------------------------------------------
Write-Host "Step 9 : Configure the Administration Component" -foregroundcolor Cyan

$adminSearchInstance = Get-SPEnterpriseSearchServiceInstance $adminServer

if($adminSearchInstance.Status -ne "Online")
{
  $adminSearchInstance | Start-SPServiceInstance
}
else
{
write-host "Admin Search Instance is Online" -foregroundcolor Green
}


$admin = ($searchApp | Get-SPEnterpriseSearchAdministrationComponent)
$admin | Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $adminSearchInstance
$admin = ($searchApp | Get-SPEnterpriseSearchAdministrationComponent)
while(-not $admin.Initialized)
{
Start-Sleep 10
$admin = ($searchApp | Get-SPEnterpriseSearchAdministrationComponent)
}

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $adminServer


Write-Host " Configure Administration Component ended " -foregroundcolor Green

Start-Sleep -s 5


#Create the Crawl and Query Components
#-------------------------------------------------------
Write-Host "Step 10 : Create the Crawl and Query Components" -foregroundcolor Cyan
$initialCrawlTopology = ($searchApp | Get-SPEnterpriseSearchCrawlTopology)
$initialQueryTopology = ($searchApp | Get-SPEnterpriseSearchQueryTopology)

#Crawl
#-------
Write-Host "=== Crawl Component ===" -foregroundcolor Cyan
$crawlTopology = ($searchApp | New-SPEnterpriseSearchCrawlTopology)
$crawlDB = Get-SPEnterpriseSearchCrawlDatabase -SearchApplication $searchApp
$crawlInstance = Get-SPEnterpriseSearchServiceInstance $crawlServer


$crawlComponent = New-SPEnterpriseSearchCrawlComponent -CrawlTopology $crawlTopology -CrawlDatabase $crawlDB -SearchServiceInstance $crawlInstance

$crawlTopology | Set-SPEnterpriseSearchCrawlTopology -Active
do
{
 Start-Sleep 5
 $crawlTopology = $searchApp | Get-SPEnterpriseSearchCrawlTopology $crawlTopology
}
while($crawlTopology.State -ne "Active")

Write-Host " Configure Crawl Component ended " -foregroundcolor Green

<# It is important to wait until the process of Crawl initiation will be finished
   After it done you can initiate the query Component #>

#Query
#--------
Write-Host "=== Query Component ===" -foregroundcolor Cyan
Start-Sleep -s 300
$queryTopology = ($searchApp | New-SPEnterpriseSearchQueryTopology -Partitions 1 )
$propDB = Get-SPEnterpriseSearchPropertyDatabase -SearchApplication $searchApp
$indexPartition = Get-SPEnterpriseSearchIndexPartition -QueryTopology $queryTopology
$indexPartition | Set-SPEnterpriseSearchIndexPartition -PropertyDatabase $propDB


$svc = Get-SPEnterpriseSearchServiceInstance $queryServer
$queryComponent = New-SPEnterpriseSearchQueryComponent -queryTopology $queryTopology -indexPartition $indexPartition -SearchServiceInstance $svc


$queryTopology | Set-SPEnterpriseSearchqueryTopology -Active
do
{
 Start-Sleep 5
 $queryTopology = $searchApp | Get-SPEnterpriseSearchqueryTopology $queryTopology
}
while($queryTopology.State -ne "Active")

Write-Host " Configure Query Component ended " -foregroundcolor Green
$initialCrawlTopology | Remove-SPEnterpriseSearchCrawlTopology -confirm:$false


# Activate the Topology
#-------------------------------
if($initialQueryTopology.State -eq "Deactivating")
{
 Write-Host "Wait for Deactivating the Query Component" -foregroundcolor Yellow
  do
  {

  }
  while($initialQueryTopology.State -eq "Deactivating")
}
else
{
  Start-Sleep -s 120
  $initialQueryTopology | Remove-SPEnterpriseSearchQueryTopology -confirm:$false
}


Write-Host " ======== The End ========" -foregroundcolor Green




You can check that if the service applications was added through the Central Admin, go to Central Administration select Application Management and then on Manage service applications you should see the Service Application you created in the list.




You can go ahead and create WebApplication via the Central Admin but take care while creating chooses an intuitive name for the DB's to the WebApplication.

In addition there is another number things that we should make  to farm run optimally:
1. Adding value tothe Registry of DisableLoopbackCheck - link to the article.
2. Create WebApplication with hostheader.
3. Editing Host File, add the IP address of the machine itself the site in IIS (for that matter to the host header you added when you've generated WebApplication without http:// prefix)

Good Luck :)

Ron Ness.