Re Provisoning SharePoint Service Applications using Powershell

Service application can reprovisoned easily with powershell scripts. This will be handy if you want reprovision service application. First we need to what are the service application in the Farm by using Get-SPServiceApplication cmdlet in powershell.

PS C:\>  Get-SPServiceApplication

DisplayName            TypeName                       Id
----------------               ------------                        --
Access Services      Access Services W... ae0360b9-1cb1-455b-8458-dac1b4e9aa95
Secure Store Service Secure Store Serv... 1d48901e-adce-4ee4-9b05-2c409aae8b1f
State Service        State Service        6ff9360a-ae0f-43a1-9f43-65c9fb8fd2d6
PerformancePoint ... PerformancePoint ... 3135520e-48c4-4f82-9a76-49fa31e96690
Visio Graphics Se... Visio Graphics Se... 9f7feb30-8dbe-4b37-9849-0a7363d31230
Managed Metadata ... Managed Metadata ... 5643614f-f292-4f01-b0e6-4b77e2cceb8f
Web Analytics Ser... Web Analytics Ser... 4c9b273c-56a7-4ca3-80ae-1ce409c80bfc
Excel Services Ap... Excel Services Ap... 1d5ffaf0-f4f8-4365-8d1c-2f2afbda6656
Security Token Se... Security Token Se... 6a2c94eb-3e7e-425a-b762-dd19bbf149fe
Application Disco... Application Disco... e9c22922-46c6-42ac-bf79-8cd3a1cce0fa
Usage and Health ... Usage and Health ... c32357b0-2b6d-4c8d-bd05-548771710713
Search Administra... Search Administra... c748b051-4311-4514-9b75-9e61a9410372
Word Automation S... Word Automation S... 10cf725c-a84e-4a94-803f-64857e1873fe
Application Regis... Application Regis... 54b0a693-05d4-4767-913d-c6b5563093c6
User Profile Serv... User Profile Serv... 0878c2cc-f671-406c-b0d0-1e4cfae7115e
Business Data Con... Business Data Con... af09a9cf-61e3-4396-bb03-340fca9d8c36
Search Service Ap... Search Service Ap... 3291026e-85c9-43b5-9bdb-532e1b186db1

Then grab the service application you want reprovision by match in powershell

PS C:\>PS C:\>  $Metadata = Get-SPServiceApplication | ?{$_ -match "Security"}$sts = Get-SPServiceApplication | ?{$_ -match "Metadata"}

Make sure the object is the correct one by looking at the property of the local variable

PS C:\>PS C:\> $Metadata PS C:\>PS C:\> $Metadata

DisplayName            TypeName                       Id
----------------               ------------                        --
Managed Metadata ... Managed Metadata ... 5643614f-f292-4f01-b0e6-4b77e2cceb8f

Then Call the provision method

PS C:\> $sts.Provision()

Hope this will help some people.