Well, sometimes things do not go as planned and you need to undo some things you did in SharePoint testing environment or for a client.

As I am currently working on a script to install Service Applications I had a need to remove 10-20 service application from my testing farm automatically.

Here is the script that can do that; it will automatically remove all service applications along with associated data.

Click here to download the script.


if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;

$seviceApps = Get-SPServiceApplication | Where {$_.TypeName -ne "Security Token Service Application" -and $_.TypeName -ne "Application Discovery and Load Balancer Service Application"}
if($seviceApps -ne $null) {
$seviceApps | ForEach-Object {Remove-SPServiceApplication $_.Id -removedata -confirm:$false}

$serviceAppProxies = Get-SpServiceApplicationProxy | Where {$_.TypeName -ne "Application Discovery and Load Balancer Service Application Proxy"}
if($serviceAppProxies -ne $null) {
$serviceAppProxies | ForEach-Object {Remove-SPServiceApplicationProxy $_.Id -removedata -confirm:$false}

Leave a Reply