I am facing similar issue when I run a powershell script on SQL Server 2008 R2 machine using Autosys job scheduler (remote machine). I would appreciate if someone can tell me how to resolve it.
On SQL Server 2008 R2 machine, there is a batchfile (Run.cmd) which contains the code:
POWERSHELL.EXE -ExecutionPolicy UnRestricted -file D:\Run\Run.ps1 -Path "D:\Run"
Run.cmd is called by Autosys Job Scheduler as a command job.
SQL Server 2008R2 machines has these 3 installed.
SQL Server 2012 Feature Pack: SQLSysClrTypes, SharedManagementObjects.msi, PowerShellTools.msi
When I run the run.cmd locally then it works as expected but when I call the run.cmd using Autosys job then it gives below error:
Cannot load Windows PowerShell snap-in C:\Program Files\Microsoft SQL Server\110\Tools\PowerShell\Modules\sqlps\Microsoft.SqlServer.Management.PSSnapins.dll because of the following error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. Loader Exceptions: Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
Further when I check GAC C:\Windows\assembly then I see the 10.0.0.0 (x86), 10.0.0.0 (AMD64) and 11.0.0.0 (AMD64) version of 'Microsoft.SqlServer.BatchParser in it.