Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
virusstorm 27-Aug-15 15:57pm    
You are most likely running into a versioning issue. If all of your SQL Servers are 2008R2, and your script and tool is looking for assemblies for 2012, then there will be missing DLL's.

Without knowing what you are trying to with the 2012 tools on a 2008R2 machine, my only suggestion would be to install the SQL Server 2012 Client Connectivity Tools on your server and see if that provides the missing DLLs.
Member 11938705 27-Aug-15 18:54pm    
Interesting part here is, run.cmd in my case when run locally works perfectly fine but when executed by Autosys command job (remotely), it fails with above error. So is this case really related to missing DLLs or something else?

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"
Member 11938705 27-Aug-15 18:55pm    
Run.ps1 (powershell script) uses import-module sqlps and invoke-sqlcmd internally.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900