While automating a lot of my SharePoint builds I came across this issue across while provisioning a few service applications within SharePoint 2010. Usually the culprits were:-

Access Service Application

Word Automation Service Application

Excel Service Application

Visio Service Application.

 

This morning, the usual suspects were back except Word Automation Service. After a few VM resets and restart of scripts, I found the culprit to be PowerShell loading up its cmdlets properly so that those executions happen properly.

The cmdlets that will usually fail are

Get-SPExcelServiceApplication

Get-SPVisioServiceApplication

New-SPVisioServiceApplication

New-SPExcelServiceApplication

New-SPAccessServiceApplication

 

The error message will display as shown below

 

Resolution:

 

Add these two lines to the beginning of your script ,

 

So if you’ve previously loaded your cmdlets the following code should be sufficient (add this to your own function or whatever):

1
2
3
Remove-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue