Powershell function to get Windows Version & Load SMO
Does anybody have a Powershell function to retrieve the Windows Server Version of a server and load the appropriate SMO assembly? The .LoadWithPartialName() method I was using before is deprecated. I will be looping through a list of servers from 2008 to 2016. It appears I have to have a load statement for each possible version. It would be good to have this in a function that I can call when needed. I'm sure somebody has done this in a clean and simple way. Thanks for any help you can offer.
I will mark this question as answered with thanks to Oleg. His suggestion was to use this command which is not version dependent.: Add-Type -AssemblyName "Microsoft.SqlServer.Management.SMO" I found that this worked on all our servers as long as I used the path to where we put that dll. Add-Type -Path 'C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies\Microsoft.SqlServer.Smo.dll' None of the references I read pointed out that you might have to use the -path option if you stash the dll somewhere other than the default location.