Blog Image

PowerShell

SharePoint Powershell Commands

GoSharePoint Website
Documentation Blog

This blog is based on SharePoint 2013 PowerShell Commands. Please visit my other blog which contains SharePoint Documentation.

Create Word Automation Services

Service Applications Posted on Tue, June 28, 2016 07:17:00

<#====================================================================

Copyright © 2015, September. Michael Pomfret

Creates the Word Automation Service

Check for existing service application and proxy

Check if application pool already exist, if not create it

====================================================================#>

#This service allows users to convert documents.

function Add-Module($strFileName){

Write-Host “Attempting to run ” $strFileName

<#====================================================================

Get SharePoint variables

====================================================================#>

Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)

If (Test-Path $strFileName){

&($strFileName)

}Else{

Write-Host “Cannot locate” $strFileName

}

}

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null

#Get default SQL server

$DefaultDatabaseServer = (Get-SPDatabase | ? { $_.Type -eq “Configuration Database” }).NormalizedDataSource

#Get SQL server instance for the User Profile Application, Social,

$DatabaseServer = $WordServerInstance

$ServiceApplicationName = “Word Automation Services”

$ServiceName = “Word Automation Services”

$DatabaseName = “Word Automation Service”

$spAppPoolName = “Word Automation Services Application Pool”

$spAppPoolAcc = $WordAppPoolAcc

$MachinesToActivate = $WordMachinesToActivate.Split(“,”).trim()

Write-Host “”

Write-Host “========================================================”

Write-Host “SharePoint 2013 – Module ‘$ServiceApplicationName’…”

Write-Host “To SharePoint Servers” $MachinesToActivate

Write-Host “Application Pool Name -” $spAppPoolName

Write-Host “Application Pool Account – -” $spAppPoolAcc

Write-Host “Database Server Instance -” $DatabaseServer

Write-Host “Configuration DB -” $ConfigDB

Write-Host “========================================================”

Write-Host “”

Start-SPAssignment -Global | Out-Null

try

{

#Check for existing service application and proxy

$ExistingServiceApp = Get-SPServiceApplication | where-object {$_.Name -eq $ServiceApplicationName}

if ($ExistingServiceApp -eq $null)

{

Write-Host ” – Creating ‘$ServiceApplicationName'”

#Check if managed account already exist, if not exit

$spManagedAccount = Get-SPManagedAccount -Identity $spAppPoolAcc -ErrorAction SilentlyContinue

if ($spManagedAccount -eq $null)

{

Write-Host -f Red “- ” $ServiceName ” Managed Account – Unable to retrieve managed account” $spAppPoolAcc

exit -1

}

#Check if application pool already exist, if not create it

$ApplicationPool = Get-SPServiceApplicationPool -Identity $spAppPoolName -ErrorAction SilentlyContinue

if ($ApplicationPool -eq $null)

{

New-SPServiceApplicationPool -Name $spAppPoolName -Account $spManagedAccount | Out-Null

}

else

{

Set-SPServiceApplicationPool $ApplicationPool -Account $spManagedAccount | Out-Null

}

#Note: Proxy is automatically created

New-SPWordConversionServiceApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName -Default | Out-Null

#Start service instances

Write-Host strTest “- Starting service instance”

foreach ($machine in $MachinesToActivate)

{

#Gets the service to determine its status

$service = $(Get-SPServiceInstance | where {$_.TypeName -match $ServiceName} | where {$_.Server -match “SPServer Name=”+$machine})

If ($service.Status -eq “Disabled”)

{

Write-Host -f Green “- Starting” $service.ID “on $machine”

Start-SPServiceInstance -Identity $service.ID | Out-Null

}

}

Write-Host “- Done creating ‘$ServiceApplicationName’.”

}else{

Write-Host -f Red ” – ServiceApplication ‘$ServiceApplicationName’ already exists.”

#Remove Application?

$RemoveApplication=read-host ‘Do you wish to remove Application? (Y/N)’

if ($RemoveApplication-eq”Y”)

{

write-host ” – Removing ‘$ServiceApplicationName’…”

Remove-SPServiceApplication $ExistingServiceApp -removedata -Confirm:$false

#Proxy is NOT automatically deleted

$ExistingServiceAppProxy = Get-SPServiceApplicationProxy | where-object {$_.Name -eq “$ServiceApplicationName Proxy”}

if ($ExistingServiceAppProxy -ne $null)

{

write-host “- Removing ‘$ServiceApplicationName proxy’…”

Remove-SPServiceApplicationProxy $ExistingServiceAppProxy -Confirm:$false

}

write-host “- Stopping service instance…”

Get-SPServiceInstance | where-object {$_.TypeName -eq $ServiceName} | Stop-SPServiceInstance -Confirm:$false | Out-Null

}

}

}

catch { write-Output $_ }

Stop-SPAssignment -Global | Out-Null



Create Visio Graphics Service

Service Applications Posted on Tue, June 28, 2016 07:16:28

<#====================================================================

Copyright © 2015, September. Michael Pomfret

Creates the Visio Graphics Service

#This service allows users to share and view Visio web drawings using Visio Services.

#Read more: http://technet.microsoft.com/en-us/library/ee524059.aspx

====================================================================#>

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

<#====================================================================

Get SharePoint variables

====================================================================#>

Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)

function Add-Module($strFileName){

Write-Host “Attempting to run ” $strFileName

If (Test-Path $strFileName){

&($strFileName)

}Else{

Write-Host “Cannot locate” $strFileName

}

}

$strInstallationFilesPath = (Split-Path ($PSCommandPath))

$ServiceApplicationName = “Visio Graphics Service”

$ServiceName = “Visio Graphics Service”

$spAppPoolName = “Visio Graphics Service Application Pool”

$spAppPoolAcc = $VisioAppPoolAcc

$CustomFilePath= $strInstallationFilesPath + “\Visio Graphics Service\”

$MachinesToActivate = $VisioMachinesToActivate.Split(“,”).trim()

#Get default SQL server

$DefaultDatabaseServer = (Get-SPDatabase | ? { $_.Type -eq “Configuration Database” }).NormalizedDataSource

#Get SQL server instance for the User Profile Application, Social,

$DatabaseServer = $VisioServerInstance

Write-Host “”

Write-Host “========================================================”

Write-Host “SharePoint 2013 – Module ‘$ServiceApplicationName’…”

Write-Host “To SharePoint Servers” $MachinesToActivate

Write-Host “Application Pool Name -” $spAppPoolName

Write-Host “Application Pool Account – -” $spAppPoolAcc

Write-Host “Database Server Instance” $DatabaseServer

Write-Host “Configuration DB” $ConfigDB

Write-Host “========================================================”

Write-Host “”

Write-Host “SharePoint 2013 – ‘$ServiceApplicationName’…”

Start-SPAssignment -Global | Out-Null

try

{

#Check for existing service application and proxy

$ExistingServiceApp = Get-SPServiceApplication | where-object {$_.Name -eq $ServiceApplicationName}

if ($ExistingServiceApp -eq $null)

{

Write-Host ” – Creating ‘$ServiceApplicationName'”

#Check if managed account already exist, if not exit

$spManagedAccount = Get-SPManagedAccount -Identity $spAppPoolAcc -ErrorAction SilentlyContinue

if ($spManagedAccount -eq $null)

{

Write-Host -f Red $strTest “- ” $ServiceName ” Managed Account – Unable to retrieve managed account” $spAppPoolAcc

exit -1

}

#Check if application pool already exist, if not create it

$ApplicationPool = Get-SPServiceApplicationPool -Identity $spAppPoolName -ErrorAction SilentlyContinue

if ($ApplicationPool -eq $null)

{

New-SPServiceApplicationPool -Name $spAppPoolName -Account $spManagedAccount | Out-Null

}

else

{

Set-SPServiceApplicationPool $ApplicationPool -Account $spManagedAccount | Out-Null

}

New-SPVisioServiceApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName | Out-Null

#Create Service Application Proxy

Write-Host ” – Creating ‘$ServiceApplicationName’ proxy”

New-SPVisioServiceApplicationProxy -Name “$ServiceApplicationName Proxy” -ServiceApplication $ServiceApplicationName | Out-Null

Add-Module($CustomFilePath + “Manage the Visio Graphics Service – Global Settings.ps1”)

#Start service instances

Write-Host ” – Starting service instance”

foreach ($machine in $MachinesToActivate)

{

#Gets the service to determine its status

$service = $(Get-SPServiceInstance | where {$_.TypeName -match $ServiceName} | where {$_.Server -match “SPServer Name=”+$machine})

If ($service.Status -eq “Disabled”)

{

Write-Host ” – Starting” $service.ID “on $machine”

Start-SPServiceInstance -Identity $service.ID | Out-Null

}

}

Write-Host ” – Done creating ‘$ServiceApplicationName’.`n”

}else{

Write-Host -f Red $strTest” – ServiceApplication ‘$ServiceApplicationName’ already exists.”

#Remove Application?

$RemoveApplication=read-host ‘Do you wish to remove Application? (Y/N)’

if ($RemoveApplication-eq”Y”)

{

write-host ” – Removing ‘$ServiceApplicationName’…”

Remove-SPServiceApplication $ExistingServiceApp -removedata -Confirm:$false

#Proxy is NOT automatically deleted

$ExistingServiceAppProxy = Get-SPServiceApplicationProxy | where-object {$_.Name -eq “$ServiceApplicationName Proxy”}

if ($ExistingServiceAppProxy -ne $null)

{

write-host ” – Removing ‘$ServiceApplicationName proxy’…”

Remove-SPServiceApplicationProxy $ExistingServiceAppProxy -Confirm:$false

}

write-host ” – Stopping service instance…”

Get-SPServiceInstance | where-object {$_.TypeName -eq $ServiceName} | Stop-SPServiceInstance -Confirm:$false | Out-Null

}

}

}

catch { write-Output $_ }

Stop-SPAssignment -Global | Out-Null



Create Work Management Service Application

Service Applications Posted on Tue, June 28, 2016 07:14:31

<#====================================================================

Copyright © 2015, September. Michael Pomfret

Creates the Work Management Service Application which provides task aggregation across work management systems, including Microsoft SharePoint Products, Microsoft Exchange Server, and Microsoft Project Server.

Check for existing service application and proxy

Check if application pool already exist, if not create it

Creates Service Application Proxy

====================================================================#>

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

<#====================================================================

Get SharePoint variables

====================================================================#>

Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)

function Add-Module($strFileName){

Write-Host “Attempting to run ” $strFileName

If (Test-Path $strFileName){

&($strFileName)

}Else{

Write-Host “Cannot locate” $strFileName

}

}

#Get default SQL server

$DefaultDatabaseServer = (Get-SPDatabase | ? { $_.Type -eq “Configuration Database” }).NormalizedDataSource

#Get SQL server instance for the User Profile Application, Social,

$DatabaseServer = $WorkServerInstance

$ServiceApplicationName = “Work Management Service Application”

$ServiceName = “Work Management Service”

$spAppPoolAcc = $AppPoolAcc

$spAppPoolName = “Work Management Service Application Pool”

$MachinesToActivate = $WorkMachinesToActivate.Split(“,”).trim()

Write-Host “”

Write-Host “========================================================”

Write-Host “SharePoint 2013 – Module ‘$ServiceApplicationName’…”

Write-Host “To SharePoint Servers” $MachinesToActivate

Write-Host “Application Pool Name -” $spAppPoolName

Write-Host “Application Pool Account – -” $spAppPoolAcc

Write-Host “Database Server Instance -” $DatabaseServer

Write-Host “Configuration DB -” $ConfigDB

Write-Host “========================================================”

Write-Host “”

Start-SPAssignment -Global | Out-Null

try

{

#Check for existing service application and proxy

$ExistingServiceApp = Get-SPServiceApplication | where-object {$_.Name -eq $ServiceApplicationName}

if ($ExistingServiceApp -eq $null)

{

Write-Host ” – Creating ‘$ServiceApplicationName'”

#Check if managed account already exist, if not exit

$spManagedAccount = Get-SPManagedAccount -Identity $spAppPoolAcc -ErrorAction SilentlyContinue

if ($spManagedAccount -eq $null)

{

Write-Host -f Red “- ” $ServiceName ” Managed Account – Unable to retrieve managed account” $spAppPoolAcc

exit -1

}

#Check if application pool already exist, if not create it

$ApplicationPool = Get-SPServiceApplicationPool -Identity $spAppPoolName -ErrorAction SilentlyContinue

if ($ApplicationPool -eq $null)

{

Write-Host “- Creating $spAppPoolName using managed account to $spManagedAccount”

New-SPServiceApplicationPool -Name $spAppPoolName -Account $spManagedAccount | Out-Null

}

else

{

Write-Host ” – Updating $ServiceApplicationName managed account to $spManagedAccount”

Set-SPServiceApplicationPool $ApplicationPool -Account $spManagedAccount | Out-Null

}

New-SPWorkManagementServiceApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName | Out-Null

#Create Service Application Proxy

Write-Host ” – Creating ‘$ServiceApplicationName’ proxy”

New-SPWorkManagementServiceApplicationProxy -Name “$ServiceApplicationName Proxy” -DefaultProxyGroup -ServiceApplication $ServiceApplicationName | Out-Null

#Start service instances

Write-Host “- Starting service instance”

foreach ($machine in $MachinesToActivate)

{

#Gets the service to determine its status

$service = $(Get-SPServiceInstance | where {$_.TypeName -match $ServiceName} | where {$_.Server -match “SPServer Name=”+$machine})

If ($service.Status -eq “Disabled”)

{

Write-Host ” – Starting” $service.ID “on $machine”

If(-eq”Live”)

{

Start-SPServiceInstance -Identity $service.ID | Out-Null

}

}else{

Write-Host -f Green “- “$service.ID “on $machine already started”

}

}

Write-Host “- Completed creating ‘$ServiceApplicationName’.”

}else{

Write-Host -f Red ” – ServiceApplication ‘$ServiceApplicationName’ already exists.”

#Remove Application?

$RemoveApplication=read-host ‘Do you wish to remove Application? (Y/N)’

if ($RemoveApplication-eq”Y”)

{

write-host “- Removing ‘$ServiceApplicationName’…”

Remove-SPServiceApplication $ExistingServiceApp -removedata -Confirm:$false

#Proxy is NOT automatically deleted

$ExistingServiceAppProxy = Get-SPServiceApplicationProxy | where-object {$_.Name -eq “$ServiceApplicationName Proxy”}

if ($ExistingServiceAppProxy -ne $null)

{

write-host “- Removing ‘$ServiceApplicationName proxy’…”

Remove-SPServiceApplicationProxy $ExistingServiceAppProxy -Confirm:$false

}

write-host “- Stopping service instance…”

Get-SPServiceInstance | where-object {$_.TypeName -eq $ServiceName} | Stop-SPServiceInstance -Confirm:$false | Out-Null

}

}

}

catch { write-Output $_ }

Stop-SPAssignment -Global | Out-Null



Create State Service Application

Service Applications Posted on Tue, June 28, 2016 07:13:47

<#====================================================================

Copyright © 2015, September. Michael Pomfret

Creates the State Service Application

Provides temporary storage of user session data for SharePoint Server components.

Read more: http://technet.microsoft.com/en-us/library/ee704548.aspx

====================================================================#>

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

<#====================================================================

Get SharePoint variables

====================================================================#>

Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)

function Add-Module($strFileName){

Write-Host “Attempting to run ” $strFileName

If (Test-Path $strFileName){

&($strFileName)

}Else{

Write-Host “Cannot locate” $strFileName

}

}

#Get default SQL server

$DefaultDatabaseServer = (Get-SPDatabase | ? { $_.Type -eq “Configuration Database” }).NormalizedDataSource

#Get SQL server instance for the User Profile Application, Social,

$DatabaseServer = $StateServerInstance

$ServiceApplicationName = “State Service Application”

$DatabaseName = ‘State Service Application’

$MachinesToActivate = $StateMachinesToActivate.Split(“,”).trim()

Write-Host “”

Write-Host “========================================================”

Write-Host “SharePoint 2013 – Module ‘$ServiceApplicationName’…”

Write-Host “To SharePoint Servers” $MachinesToActivate

Write-Host “Application Pool Name -” $spAppPoolName

Write-Host “Application Pool Account – -” $spAppPoolAcc

Write-Host “Database Server Instance -” $DatabaseServer

Write-Host “Configuration DB -” $ConfigDB

Write-Host “========================================================”

Write-Host “”

Start-SPAssignment -Global | Out-Null

try

{

#Check for existing service application and proxy

$ExistingServiceApp = Get-SPServiceApplication | where-object {$_.Name -eq $ServiceApplicationName}

if ($ExistingServiceApp -eq $null)

{

Write-Host ” – Creating ‘$ServiceApplicationName'”

New-SPStateServiceDatabase -Name $DatabaseName | Out-Null

New-SPStateServiceApplication -Name “State Service Application” -Database $DatabaseName | Out-Null

Get-SPStateServiceDatabase | Initialize-SPStateServiceDatabase | Out-Null

#Create proxy

write-host ” – Creating ‘$ServiceApplicationName proxy'”

Get-SPStateServiceApplication | New-SPStateServiceApplicationProxy -Name “$ServiceApplicationName Proxy” | Out-Null

Write-Host ” – Done creating ‘$ServiceApplicationName’.`n”

}else{

Write-Host -f Red $strTest” – ServiceApplication ‘$ServiceApplicationName’ already exists.”

#Remove Application?

$RemoveApplication=read-host ‘Do you wish to remove Application? (Y/N)’

if ($RemoveApplication-eq”Y”)

{

write-host ” – Removing ‘$ServiceApplicationName’…”

Remove-SPServiceApplication $ExistingServiceApp -removedata -Confirm:$false

#Proxy is NOT automatically deleted

$ExistingServiceAppProxy = Get-SPServiceApplicationProxy | where-object {$_.Name -eq “$ServiceApplicationName Proxy”}

if ($ExistingServiceAppProxy -ne $null)

{

write-host ” – Removing ‘$ServiceApplicationName proxy’…”

Remove-SPServiceApplicationProxy $ExistingServiceAppProxy -Confirm:$false

}

write-host ” – Stopping service instance…”

Get-SPServiceInstance | where-object {$_.TypeName -eq $ServiceName} | Stop-SPServiceInstance -Confirm:$false | Out-Null

}

}

}

catch { write-Output $_ }

Stop-SPAssignment -Global | Out-Null



Create Search Service Application

Service Applications Posted on Tue, June 28, 2016 07:11:32

<#====================================================================

Copyright © 2015, September. Michael Pomfret

Creates the Search Service Application

Enables Enterprise Search. Needs Usage Service Application to be created first or creates one itself if missing.

====================================================================#>

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

<#====================================================================

Get SharePoint variables

====================================================================#>

Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)

function Add-Module($strFileName){

Write-Host “Attempting to run ” $strFileName

If (Test-Path $strFileName){

&($strFileName)

}Else{

Write-Host “Cannot locate” $strFileName

}

}

#Enables Enterprise Search. Needs Usage Service Application to be created first or creates one itself if missing.

$ServiceApplicationName = “Search Service Application”

$ServiceName = “Search Service Application”

$IndexLocation = $SearchIndexLocation #Folder has to be empty AND has to exist!

$DatabaseName = “Search Service Application”

$spAppPoolName = “Search Service Application Pool”

$spContentAccessAcc = $CrawlAcc

$spContentAccessPwd = $CrawlPassword

$ServerName=$SearchServerName

#Get default SQL server

$DefaultDatabaseServer = (Get-SPDatabase | ? { $_.Type -eq “Configuration Database” }).NormalizedDataSource

#Get SQL server instance for the User Profile Application, Social,

$DatabaseServer = $SearchServerInstance

Write-Host “”

Write-Host “========================================================”

Write-Host “SharePoint 2013 – Adding ‘$ServiceApplicationName’…”

Write-Host “To SharePoint Server” $ServerName

Write-Host “Application Pool Name -” $spAppPoolName

Write-Host “Index Location ” $IndexLocation

Write-Host “Application Pool Account” $SearchAppPoolAcc

Write-Host “Crawl Account” $CrawlAcc

Write-Host “========================================================”

Write-Host “”

Start-SPAssignment -Global | Out-Null

try

{

#Check for existing service application and proxy

$ExistingServiceApp = Get-SPServiceApplication | where-object {$_.Name -eq $ServiceApplicationName}

if ($ExistingServiceApp -eq $null)

{

mkdir -Path $SearchIndexLocation -Force | Out-Null

Write-Host “- Creating ‘$ServiceApplicationName'”

#Start service instances

write-host “- Starting service instances”

Start-SPEnterpriseSearchServiceInstance $ServerName

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $ServerName

#Check if managed account already exist, if not exit

$spManagedAccount = Get-SPManagedAccount -Identity $SearchAppPoolAcc -ErrorAction SilentlyContinue

if ($spManagedAccount -eq $null)

{

Write-Host -f Red “- ” $ServiceName ” Managed Account – Unable to retrieve managed account” $SearchAppPoolAcc

exit -1

}

#Check if managed account already exist, if not exit

$spManagedAccount = Get-SPManagedAccount -Identity $SearchAppPoolAcc -ErrorAction SilentlyContinue

if ($spManagedAccount -eq $null)

{

Write-Host -f Red “- ” $ServiceName ” Managed Account – Unable to retrieve managed account” $SearchAppPoolAcc

exit -1

} $ApplicationPool = Get-SPServiceApplicationPool -Identity $spAppPoolName -ErrorAction SilentlyContinue

if ($ApplicationPool -eq $null)

{

New-SPServiceApplicationPool -Name $spAppPoolName -Account $spManagedAccount | Out-Null

}

else

{

Set-SPServiceApplicationPool $ApplicationPool -Account $spManagedAccount | Out-Null

}

#Search Application

Write-Host “- Creating Search Service Application”

$ServiceApplication = New-SPEnterpriseSearchServiceApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName

#Create proxy

Write-Host “- Creating ‘$ServiceApplicationName’ proxy”

New-SPEnterpriseSearchServiceApplicationProxy -Name “$ServiceApplicationName Proxy” -SearchApplication $ServiceApplicationName | Out-Null

#Get the search instance

$searchInstance = Get-SPEnterpriseSearchServiceInstance $ServerName

#Topology

Write-Host “- Creating new search topology”

$InitialSearchTopology = $ServiceApplication | Get-SPEnterpriseSearchTopology -Active

$SearchTopology = $ServiceApplication | New-SPEnterpriseSearchTopology

#Administration + Processing Components

Write-Host “- Creating Administration Component”

New-SPEnterpriseSearchAdminComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance | Out-Null

Write-Host “- Creating Analytics Processing Component”

New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance | Out-Null

Write-Host “- Creating Content Processing Component”

New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance | Out-Null

Write-Host “- Creating Query Processing Component”

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance | Out-Null

#Crawl

Write-Host “- Creating Crawl Component”

New-SPEnterpriseSearchCrawlComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance | Out-Null

#Index (Query)

Write-Host “- Creating Query Component”

#$IndexPartition= 1 #(Get-SPEnterpriseSearchIndexPartition -QueryTopology $SearchTopology)

New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance -RootDirectory $IndexLocation | Out-Null #-IndexPartition $IndexPartition

#Activates a Search Topology and requires all components attached to a topology

Write-Host “- Activating new Search Topology”

$SearchTopology | Set-SPEnterpriseSearchTopology

try

{

$InitialSearchTopology.Synchronize()

}

catch { }

Write-Host “- Waiting for the old crawl topology to become inactive..” -NoNewline

do {

Write-Host -NoNewline .;Start-Sleep 6;} while ($InitialSearchTopology.State -ne “Inactive”)

$InitialSearchTopology | Remove-SPEnterpriseSearchTopology -Confirm:$false

Write-Host

#Set Content Access account

Write-Host “- Setting Content Access Account”

$c = New-Object Microsoft.Office.Server.Search.Administration.Content($ServiceApplication)

$c.SetDefaultGatheringAccount($spContentAccessAcc, (ConvertTo-SecureString $spContentAccessPwd -AsPlainText -force))

Write-Host “- Done creating ‘$ServiceApplicationName’.`n”

}

}

catch { write-Output $_ }

Stop-SPAssignment -Global | Out-Null



Create PerformancePoint Service Application

Service Applications Posted on Tue, June 28, 2016 07:11:06

<#====================================================================

Copyright © 2015, September. Michael Pomfret

Creates the PerformancePoint Service Application.ps1

This service allows you to monitor and analyze your business by using dashboards, reports or KPIs.

Read more: http://technet.microsoft.com/en-us/library/ee681490

====================================================================#>

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

<#====================================================================

Get SharePoint variables

====================================================================#>

Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)

function Add-Module($strFileName){

Write-Host “Attempting to run ” $strFileName

If (Test-Path $strFileName){

&($strFileName)

}Else{

Write-Host “Cannot locate” $strFileName

}

}

$ServiceApplicationName = “PerformancePoint Service Application”

$ServiceName = “PerformancePoint Service”

$DatabaseName = ‘PerformancePoint Service Application’

$spAppPoolName = “PerformancePoint Service Application Pool”

$spAppPoolAcc = $PerformancePointAppPoolAcc

#Get default SQL server

$DefaultDatabaseServer = (Get-SPDatabase | ? { $_.Type -eq “Configuration Database” }).NormalizedDataSource

#Get SQL server instance for the User Profile Application, Social,

$DatabaseServer = $PerformancePointServerInstance

$MachinesToActivate = $PerformancePointMachinesToActivate.Split(“,”).trim()

Write-Host “”

Write-Host “========================================================”

Write-Host “SharePoint 2013 – Module ‘$DefaultAppPoolName’…”

Write-Host “To SharePoint Servers” $MachinesToActivate

Write-Host “Application Pool Name -” $spAppPoolName

Write-Host “Application Pool Account – -” $spAppPoolAcc

Write-Host “Database Server Instance -” $DatabaseServer

Write-Host “Configuration DB -” $ConfigDB

Write-Host “========================================================”

Write-Host “”

Start-SPAssignment -Global | Out-Null

try

{

#Check for existing service application and proxy

$ExistingServiceApp = Get-SPServiceApplication | where-object {$_.Name -eq $ServiceApplicationName}

if ($ExistingServiceApp -eq $null)

{

Write-Host $strTest “- Creating ‘$ServiceApplicationName'”

#Check if managed account already exist, if not exit

$spManagedAccount = Get-SPManagedAccount -Identity $spAppPoolAcc -ErrorAction SilentlyContinue

if ($spManagedAccount -eq $null)

{

Write-Host -f Red $strTest “- ” $ServiceName ” Managed Account – Unable to retrieve managed account” $spAppPoolAcc

exit -1

}

#Check if application pool already exist, if not create it

$ApplicationPool = Get-SPServiceApplicationPool -Identity $spAppPoolName -ErrorAction SilentlyContinue

if ($ApplicationPool -eq $null)

{

New-SPServiceApplicationPool -Name $spAppPoolName -Account $spManagedAccount | Out-Null

}

else

{

Set-SPServiceApplicationPool $ApplicationPool -Account $spManagedAccount | Out-Null

write-host $ApplicationPool

}

New-SPPerformancePointServiceApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName | Out-Null

#Create Service Application Proxy

Write-Host $strTest “- Creating ‘$ServiceApplicationName’ proxy”

New-SPPerformancePointServiceApplicationProxy -Default -Name “$ServiceApplicationName Proxy” -ServiceApplication $ServiceApplicationName | Out-Null

#Start service instances

Write-Host $strTest “- Starting service instance”

foreach ($machine in $MachinesToActivate)

{

#Gets the service to determine its status

$service = $(Get-SPServiceInstance | where {$_.TypeName -match $ServiceName} | where {$_.Server -match “SPServer Name=”+$machine})

If ($service.Status -eq “Disabled”)

{

Write-Host -f Green $strTest “- Starting” $service.ID “on $machine”

Start-SPServiceInstance -Identity $service.ID | Out-Null

}

}

Write-Host -f Green $strTest “- Created ‘$ServiceApplicationName’.”

}else{

Write-Host -f Red $strTest” – ServiceApplication ‘$ServiceApplicationName’ already exists.”

#Remove Application?

$RemoveApplication=read-host ‘Do you wish to remove Application? (Y/N)’

if ($RemoveApplication-eq”Y”)

{

write-host $strTest” – Removing ‘$ServiceApplicationName’…”

Remove-SPServiceApplication $ExistingServiceApp -removedata -Confirm:$false

#Proxy is NOT automatically deleted

$ExistingServiceAppProxy = Get-SPServiceApplicationProxy | where-object {$_.Name -eq “$ServiceApplicationName Proxy”}

if ($ExistingServiceAppProxy -ne $null)

{

write-host $strTest “- Removing ‘$ServiceApplicationName proxy’…”

Remove-SPServiceApplicationProxy $ExistingServiceAppProxy -Confirm:$false

}

write-host $strTest “- Stopping service instance…”

Get-SPServiceInstance | where-object {$_.TypeName -eq $ServiceName} | Stop-SPServiceInstance -Confirm:$false | Out-Null

}

}

}

catch { write-Output $_ }

Stop-SPAssignment -Global | Out-Null



Create Managed Metadata Service

Service Applications Posted on Tue, June 28, 2016 07:10:47

<#====================================================================

Copyright © 2015, September. Michael Pomfret

Creates the Managed Metadata Service

Allows you to manage taxonomy hierarchies, keywords, the social tagging infrastructure as well as Content Type publishing.

Read more: http://technet.microsoft.com/en-us/library/ee424403.aspx

====================================================================#>

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

<#====================================================================

Get SharePoint variables

====================================================================#>

Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)

function Add-Module($strFileName){

Write-Host “Attempting to run ” $strFileName

If (Test-Path $strFileName){

&($strFileName)

}Else{

Write-Host “Cannot locate” $strFileName

}

}

#Get default SQL server

$DefaultDatabaseServer = (Get-SPDatabase | ? { $_.Type -eq “Configuration Database” }).NormalizedDataSource

#Get SQL server instance for the User Profile Application, Social,

$DatabaseServer = $ManagedMetadataServerInstance

$ServiceApplicationName = “Managed Metadata Service”

$ServiceName = “Managed Metadata Web Service”

$DatabaseName = ‘Managed Metadata Service’

$spAppPoolName = “Managed Metadata Service Application Pool”

$spAppPoolAcc = $ManagedMetadataAppPoolAcc

$MachinesToActivate = $ManagedMetadataMachinesToActivate.Split(“,”).trim()

Write-Host “”

Write-Host “========================================================”

Write-Host “SharePoint 2013 – Module ‘$ServiceApplicationName’…”

Write-Host “To SharePoint Servers” $MachinesToActivate

Write-Host “Application Pool Name -” $spAppPoolName

Write-Host “Application Pool Account -” $spAppPoolAcc

Write-Host “Database Server Instance” $DatabaseServer

Write-Host “Configuration DB” $ConfigDB

Write-Host “========================================================”

Write-Host “”

Start-SPAssignment -Global | Out-Null

try

{

#Check for existing service application and proxy

$ExistingServiceApp = Get-SPServiceApplication | where-object {$_.Name -eq $ServiceApplicationName}

if ($ExistingServiceApp -eq $null)

{

Write-Host ” – Creating ‘$ServiceApplicationName'”

#Check if managed account already exist, if not exit

$spManagedAccount = Get-SPManagedAccount -Identity $spAppPoolAcc -ErrorAction SilentlyContinue

if ($spManagedAccount -eq $null)

{

Write-Host -f Red $strTest “- ” $ServiceName ” Managed Account – Unable to retrieve managed account” $spAppPoolAcc

exit -1

}

#Check if application pool already exist, if not create it

$ApplicationPool = Get-SPServiceApplicationPool -Identity $spAppPoolName -ErrorAction SilentlyContinue

if ($ApplicationPool -eq $null)

{

New-SPServiceApplicationPool -Name $spAppPoolName -Account $spManagedAccount | Out-Null

}

else

{

Set-SPServiceApplicationPool $ApplicationPool -Account $spManagedAccount | Out-Null

}

New-SPMetadataServiceApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName | Out-Null

#Create Service Application Proxy

Write-Host ” – Creating ‘$ServiceApplicationName’ proxy”

New-SPMetadataServiceApplicationProxy -Name “$ServiceApplicationName Proxy” -DefaultProxyGroup -ServiceApplication $ServiceApplicationName | Out-Null

#Start service instances

Write-Host ” – Starting service instance”

foreach ($machine in $MachinesToActivate)

{

#Gets the service to determine its status

$service = $(Get-SPServiceInstance | where {$_.TypeName -match $ServiceName} | where {$_.Server -match “SPServer Name=”+$machine})

If ($service.Status -eq “Disabled”)

{

Write-Host ” – Starting” $service.ID “on $machine”

Start-SPServiceInstance -Identity $service.ID | Out-Null

}

}

Write-Host ” – Done creating ‘$ServiceApplicationName’.`n”

}else{

Write-Host -f Red $strTest” – ServiceApplication ‘$ServiceApplicationName’ already exists.”

#Remove Application?

$RemoveApplication=read-host ‘Do you wish to remove Application? (Y/N)’

if ($RemoveApplication-eq”Y”)

{

write-host ” – Removing ‘$ServiceApplicationName’…”

Remove-SPServiceApplication $ExistingServiceApp -removedata -Confirm:$false

#Proxy is NOT automatically deleted

$ExistingServiceAppProxy = Get-SPServiceApplicationProxy | where-object {$_.Name -eq “$ServiceApplicationName Proxy”}

if ($ExistingServiceAppProxy -ne $null)

{

write-host ” – Removing ‘$ServiceApplicationName proxy’…”

Remove-SPServiceApplicationProxy $ExistingServiceAppProxy -Confirm:$false

}

write-host ” – Stopping service instance…”

Get-SPServiceInstance | where-object {$_.TypeName -eq $ServiceName} | Stop-SPServiceInstance -Confirm:$false | Out-Null

}

}

}

catch { write-Output $_ }

Stop-SPAssignment -Global | Out-Null



Create Create App Management Service

Service Applications Posted on Tue, June 28, 2016 07:09:25

<#====================================================================

Copyright © 2015, September. Michael Pomfret

Creates the Service Applications\App Management Service

Allows you to install apps from the internal App Catalog or the public SharePoint Store.

Read more: http://technet.microsoft.com/en-us/library/fp161236(v=office.15).aspx

====================================================================#>

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

function Add-Module($strFileName){

Write-Host “Attempting to run ” $strFileName

If (Test-Path $strFileName){

&($strFileName)

}Else{

Write-Host “Cannot locate” $strFileName

}

}

<#====================================================================

Get SharePoint variables

====================================================================#>

Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)

$ServiceApplicationName = “App Management Service”

$ServiceName = “App Management Service”

$DatabaseName = “App Management”

$spAppPoolName = “App Management Service Application Pool”

$spAppPoolAcc = $AppManagementAppPoolAcc

$ConfigDB = “SharePoint_Configuration”

$MachinesToActivate = $AppManagementMachinesToActivate.Split(“,”).trim()

#Get default SQL server

$DefaultDatabaseServer = (Get-SPDatabase | ? { $_.Type -eq “Configuration Database” }).NormalizedDataSource

#Get SQL server instance for the User Profile Application, Social,

$DatabaseServer = $AppManagementServerInstance

Write-Host “”

Write-Host “========================================================”

Write-Host “SharePoint 2013 – Module ‘$ServiceApplicationName’…”

Write-Host “To SharePoint Servers” $MachinesToActivate

Write-Host “Application Pool Name -” $spAppPoolName

Write-Host “Application Pool Account -” $spAppPoolAcc

Write-Host “Database Server Instance -” $DatabaseServer

Write-Host “Configuration DB -” $ConfigDB

Write-Host “========================================================”

Write-Host “”

start-SPAssignment -Global | Out-Null

try

{

#Check for existing service application and proxy

$ExistingServiceApp = Get-SPServiceApplication | where-object {$_.Name -eq $ServiceApplicationName}

if ($ExistingServiceApp -eq $null)

{

Write-Host -f White $strTest” – Creating ‘$ServiceApplicationName'”

#Check if application pool already exist, if not create it

$spManagedAccount = Get-SPManagedAccount -Identity $spAppPoolAcc -ErrorAction SilentlyContinue

#Check if managed account already exist, if not exit

$spManagedAccount = Get-SPManagedAccount -Identity $spAppPoolAcc -ErrorAction SilentlyContinue

if ($spManagedAccount -eq $null)

{

Write-Host -f Red $strTest “- ” $ServiceName ” Managed Account – Unable to retrieve managed account” $spAppPoolAcc

exit -1

}

$ApplicationPool = Get-SPServiceApplicationPool -Identity $spAppPoolName -ErrorAction SilentlyContinue

if ($ApplicationPool -eq $null)

{

New-SPServiceApplicationPool -Name $spAppPoolName -Account $spManagedAccount | Out-Null

}

else

{

Set-SPServiceApplicationPool $ApplicationPool -Account $spManagedAccount | Out-Null

}

$SA = New-SPAppManagementServiceApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName

#Create Service Application Proxy

Write-Host -f Green $strTest ” – Creating ‘$ServiceApplicationName’ proxy”

New-SPAppManagementServiceApplicationProxy -name “$ServiceApplicationName Proxy” -ServiceApplication $SA | Out-Null

#Start service instances

Write-Host $strTest “- Starting service instance”

foreach ($machine in $MachinesToActivate)

{

#Gets the service to determine its status

$service = $(Get-SPServiceInstance | where {$_.TypeName -match $ServiceName} | where {$_.Server -match “SPServer Name=”+$machine})

If ($service.Status -eq “Disabled”)

{

Write-Host -f Green $strTest “- Starting” $service.ID “on $machine”

Start-SPServiceInstance -Identity $service.ID | Out-Null

}

}

Write-Host -f Green $strTest “- Done creating ‘$ServiceApplicationName’.”

}else{

Write-Host -f Red $strTest “- ServiceApplication ‘$ServiceApplicationName’ already exists.”

#Remove Application?

$RemoveApplication=read-host ‘Do you wish to remove Application? (Y/N)’

if ($RemoveApplication-eq”Y”)

{

write-host ” – Removing ‘$ServiceApplicationName’…”

Remove-SPServiceApplication $ExistingServiceApp -removedata -Confirm:$false

#Proxy is NOT automatically deleted

$ExistingServiceAppProxy = Get-SPServiceApplicationProxy | where-object {$_.Name -eq “$ServiceApplicationName Proxy”}

if ($ExistingServiceAppProxy -ne $null)

{

write-host ” – Removing ‘$ServiceApplicationName proxy’…”

Remove-SPServiceApplicationProxy $ExistingServiceAppProxy -Confirm:$false

}

write-host ” – Stopping service instance…”

Get-SPServiceInstance | where-object {$_.TypeName -eq $ServiceName} | Stop-SPServiceInstance -Confirm:$false | Out-Null

}

}

}

catch { write-Output $_ }

Stop-SPAssignment -Global | Out-Null



Next »