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 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 SQL Server client alias

SQL Posted on Tue, June 28, 2016 07:13:22

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

Copyright © 2015, September. Michael Pomfret

Adds the SQL Server client alias

The script only targets the server you are running the script on

and does the following:

-Adds the SQL Server client alias

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

#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

}

}

Write-Host “SharePoint 2013 – Adding the SQL Server client alias…”

#This is the name of your SQL Alias

$AliasName = “SPFarmAlias”

#This is the name of your SQL server (the actual name!)

# In this case we’re using the SQL Server name is defined in the SharePoint Variables text file

#These are the two Registry locations for the SQL Alias locations

$x86 = “HKLM:\Software\Microsoft\MSSQLServer\Client\ConnectTo”

$x64 = “HKLM:\Software\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo”

#We’re going to see if the ConnectTo key already exists, and create it if it doesn’t.

if ((test-path -path $x86) -ne $True)

{

write-host “$x86 doesn’t exist”

New-Item $x86

}

if ((test-path -path $x64) -ne $True)

{

write-host “$x64 doesn’t exist”

New-Item $x64

}

#Adding the TCPIP Alias

$TCPAlias = (“DBMSSOCN,” + $DBServer)

#Creating our TCP/IP Aliases

New-ItemProperty -Path $x86 -Name $AliasName -PropertyType String -Value $TCPAlias

New-ItemProperty -Path $x64 -Name $AliasName -PropertyType String -Value $TCPAlias

# Open cliconfig to verify the aliases

#Start-Process C:\Windows\System32\cliconfg.exe

#Start-Process C:\Windows\SysWOW64\cliconfg.exe



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



Create Business Data Connectivity Service

Service Applications Posted on Tue, June 28, 2016 07:08:34

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

Copyright © 2015, September. Michael Pomfret

Creates the Business Data Connectivity Service.ps1

Allows you to connect to and interact with external data.

Read more: http://technet.microsoft.com/en-us/library/ee661740.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”)

#Get default SQL server

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

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

$DatabaseServer = $BDCServerInstance

$ServiceApplicationName = “Business Data Connectivity Service”

$ServiceName = “Business Data Connectivity Service”

$DatabaseName = “Business Data Connectivity Service”

$spAppPoolName = “BDC Service Application Pool”

$spAppPoolAcc = $BDCAppPoolAcc

$MachinesToActivate = $BDCMachinesToActivate.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 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

}

#Note: Proxy is automatically created

New-SPBusinessDataCatalogServiceApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName | 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 $strTest “- Starting” $service.ID “on $machine”

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

}

}

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

}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 $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 “- 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 Access Services

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

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

Copyright © 2015, September. Michael Pomfret

Create the Access Services

Allows users to publish a Microsoft Access 2013 Web database to a SharePoint site.

Read more: http://technet.microsoft.com/en-us/library/ee748653.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

}

}

$ServiceApplicationName = “Access Services”

$ServiceName = “Access Services”

$spAppPoolName = “Access Services Application Pool”

$spAppPoolAcc = $AccessAppPoolAcc

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

Write-Host “”

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

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

Write-Host “To SharePoint Servers” $MachinesToActivate

Write-Host “Application Pool Name -” $spAppPoolName

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

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

}

#Note: Proxy is automatically created

New-SPAccessServicesApplication -Name $ServiceApplicationName -ApplicationPool $spAppPoolName | 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 $strTest “- Starting” $service.ID “on $machine”

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

}

}

Write-Host $strTest “- 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 $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



« PreviousNext »