Pages

Thursday, December 4, 2014

Getting SQLPSX to work with SQL Server 2012

A few years ago, I wrote PowerShell scripts to assist our IT Risk department with auditing and ID management. With the deployment of SQL Server 2012 in our environment those scripts are starting to show their age. 

The scripts were designed to run from a central server and they use SQL Server PowerShell Extensions version 1.6.1. 

The scripts are throwing errors when trying to connect to SQL Server 2012 instances.

The SMO assemblies are loaded with the following code by LibrarySmo.ps1:



If I run this bit of code on our central server it returns the Version 10 SMO assemblies that allow it to connect to SQL Server 2008 R2 and below.

Running this code on my laptop or server that has the SQL Server 2012 tools installed returns the Version 11 SMO assemblies which allow the scripts to run on SQL Server 2012.

In addition, if the scripts are copied to a server with SQL Server 2012 installed, they run successfully because the code above is loading the later version of the SMO assemblies.

So, the fix for our central server is to either install the SQL Server 2012 client tools or just the compatible SMO assemblies. We now know we need to keep the central server up to date with the latest assemblies to keep these scripts working.

Helpful references:
http://sqlpsx.codeplex.com/discussions/353631
http://sqlserverpowershell.com/2012/07/24/sqlpsx-sql-server-2012/