Monday 4 January 2016

Create Service Applications Using Powershell


Below is the Powershell script which will create basic Service Applications for SharePoint 2013 



cls
asnp "*sh*"

Write-Progress -Activity "Instantiating Variable " -Status  "Done Variable Instantiation"

$databaseServerName = "toolsteam"
$saAppPoolName = "SharePoint AppPool Services"
$appPoolUserName = "Toolsteam0\spapppool"

   
## Service Application Service Names ##

$stateService="State Service Application"

$metadataSAName = "Managed Metadata Web Service"

$usageSAName = "Usage and Health Data Collection Service"

$userProfileSAName = "User Profile Synchronization Service"

   
$saAppPool = Get-SPServiceApplicationPool -Identity $saAppPoolName -ErrorAction SilentlyContinue

if($saAppPool -eq $null)
{

  Write-Progress -Activity "Creating Service Application Pool..." -Status  "Application Pool Creating Please Wait..."
 
  $appPoolAccount = Get-SPManagedAccount -Identity $appPoolUserName -ErrorAction SilentlyContinue

 

    if($appPoolAccount -eq $null)
  {
     
     Write-Progress -Activity "Creating AppPoolAccount" -Status  "AppPool Created" $appPoolAccount

     $appPoolCred = Get-Credential $appPoolUserName

     $appPoolAccount = New-SPManagedAccount -Credential $appPoolCred
  }
 
  New-SPServiceApplicationPool -Name $saAppPoolName -Account $appPoolAccount

  Write-Host $saAppPoolName "is Created "
     
}
# Create the  State Service application

Write-Progress -Activity "Creating State Service ." -Status  "State Service Creating Please Wait......"
 
New-SPStateServiceApplication -Name $stateService

Get-SPStateServiceApplication | New-SPStateServiceApplicationProxy -DefaultProxyGroup

Get-SPStateServiceApplication | New-SPStateServiceDatabase -Name "StateSterviceDB"

Get-SPDatabase| ? {$_.Type -eq "Microsoft.Office.Server.Administration.StateDatabase"} | Initialize-SPStateServiceDatabase


# Create the Usage service application


Write-Progress -Activity "Creating Usage Service and Proxy..." -Status  "Usage Service and Proxy...Creaated"

Write-Host "Creating Usage Service and Proxy..."

$serviceInstance = Get-SPUsageService

New-SPUsageApplication -Name $usageSAName -DatabaseServer $databaseServerName -DatabaseName "UsageDB" -UsageService $serviceInstance

$proxy=Get-SPServiceApplicationProxy | ? { $_.TypeName -eq "Usage and Health Data Collection Proxy"}

$proxy.Provision();

Write-Host $usageSAName "is Created"


# Create the Managed MetaData service application

Write-Progress -Activity "Managed MetaData Service and Proxy..." -Status  "Managed MetaData Service and Proxy...Creating Please Wait"

Write-Host "Creating Menaged MetaData Service Application"

$mmsapp = New-SPMetadataServiceApplication -Name "Managed Metadata Service" -ApplicationPool  $saAppPoolName -DatabaseName "ManagedMetadataDB"

# Create the service proxy
New-SPMetadataServiceApplicationProxy -Name "Managed Metadata Service Proxy" -ServiceApplication $mmsapp -DefaultProxyGroup

Write-Host $mmsapp "is created "


# Create the User Profile Service Application


Write-Progress -Activity "Creating UserProfile Service Application..." -Status  "Usage Service and Proxy...Creating Please Wait"

Write-Host "Creating UserProfile Service Application"

$upa = New-SPProfileServiceApplication -Name "User Profile Service" -ApplicationPool $saAppPoolName -ProfileDBName "ProfileDB" -SocialDBName "SocialDB" -ProfileSyncDBName "SyncDB"

# Create the service proxy

New-SPProfileServiceApplicationProxy -Name "User Profile Service Proxy" -ServiceApplication $upa -DefaultProxyGroup

Write-Host $upa "Is Created "






No comments:

Post a Comment