Link to home
Start Free TrialLog in
Avatar of Marc Davis
Marc DavisFlag for United States of America

asked on

Powershell and multiple SQL Servers and use highest .datpac.

Hi all,

How can I obtain the highest version of a .dacpac to use on a machine given the machine has multiple versions of SQL server installed?

So, we know where is a possibility of:

'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130\Microsoft.SqlServer.Dac.dll'
'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\120\Microsoft.SqlServer.Dac.dll'
'C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\Microsoft.SqlServer.Dac.dll'
'C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin\Microsoft.SqlServer.Dac.dll'
'C:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin\Microsoft.SqlServer.Dac.dll'
'C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\Microsoft.SqlServer.Dac.dll'

These could all be on the same machine or let's say even 3 of these (2 is just an example).

We know that any of the 2 first ones would be the highest of all of them so we if out of the first 2 if the machine had them it would take the one with the highest SQLDB\DAC which is the one with the "130" directory.

If it didn't have the first 2 but the others it would take the one with the "Microsoft SQ Server" with the "140"  but if the machine didn't have the "140" SQL Server it would look at the one with the "130" directory, etc.

How can I do a Powershell script that will iterate through all those directories (and may not be in that order) and give me the directory with the highest DAC pack numbered directory?

Please let me know on that.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marc Davis

ASKER

The one thing with this is that it iterates through every folder in the "C:\Program Files" and "C:\Program Files (x86)" and that could take some time.

But outside of that it works great and thanks!