Search code examples
powershellssas

How do I import the correct version of SQLASCMDLETS in PowerShell?


I'm trying to write a PowerShell script to automate some SQL Server Analysis Services tasks. However there are two copies of SQLASCMDLETS on my system:

PS C:\Windows\system32> get-module -ListAvailable -name 'SQLASCMDLETS' | Format-Table -Property Name, Version, Path

Name         Version Path                                                                                                   
----         ------- ----                                                                                                   
SQLASCMDLETS 1.0     C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLASCMDLETS\SQLASCMDLETS.psd1
SQLASCMDLETS 1.0     C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\SQLASCMDLETS\SQLASCMDLETS.psd1

The older version under the \110\ folder contains a bug which incorrectly splits the query into invalid statements and the script fails with an error. I've confirmed that the later version under the \120\ folder works correctly, by changing the extension of the older version and restarting the PS session. However, that is not an ideal solution if this script is to be shared with other users.

Given that both copies have the same name and version number, how can I make sure I use the correct version when I import this module?


Solution

  • Try this:

    Import-Module -Name 'C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\SQLASCMDLETS\SQLASCMDLETS.psd1'