Skip to content

Instantly share code, notes, and snippets.

@shaneis
Last active June 5, 2017 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaneis/19308a7c5fb68b584b6a2a0ee0ec500b to your computer and use it in GitHub Desktop.
Save shaneis/19308a7c5fb68b584b6a2a0ee0ec500b to your computer and use it in GitHub Desktop.
Gets the latest SQL Server SMO on the system and creates the Add-Type -AssemblyName parameter
# Load the assemblies to work for the latest version of SQL Server on the machine
$AddTypeValue = Get-ChildItem -Path C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Smo\ |
Sort-Object -Property LastWriteTimeUtc |
Select-Object -ExpandProperty Name -First 1;
[string]$AssemblyValue = "Microsoft.SqlServer.Smo, Version=$($AddTypeValue.Substring(0, 8)), culture=neutral, PublicKeyToken=$($AddTypeValue.Substring($AddTypeValue.LastIndexOf('__') + 2))";
Add-Type -AssemblyName $AssemblyValue;
@shaneis
Copy link
Author

shaneis commented Jun 5, 2017

....AAAAANNDDDD this doesn't work...

@shaneis
Copy link
Author

shaneis commented Jun 5, 2017

The new version here does though!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment