3

I am trying to use the SqlServer PowerShell module, available on the PowerShell Gallery.

After installing, either to -Scope CurrentUser or in an admin session, doing Import-Module SqlServer only results in three commands being imported into the session:

PS C:\Users\nreiling> Get-Command -Module SqlServer

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Decode-SqlName                                     21.0.17262 sqlserver
Alias           Encode-SqlName                                     21.0.17262 sqlserver
Function        SQLSERVER:                                         21.0.17262 sqlserver

This is in spite of the fact that doing (Get-Module -Name SqlServer -ListAvailable)[0].ExportedCommands.Values lists out all of the commands that are supposed to be included:

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Add-RoleMember                                     21.0.17262 SqlServer
Cmdlet          Add-SqlAvailabilityDatabase                        21.0.17262 SqlServer
Cmdlet          Add-SqlAvailabilityGroupListenerStaticIp           21.0.17262 SqlServer
Cmdlet          Add-SqlAzureAuthenticationContext                  21.0.17262 SqlServer
Cmdlet          Add-SqlColumnEncryptionKeyValue                    21.0.17262 SqlServer
Cmdlet          Add-SqlFirewallRule                                21.0.17262 SqlServer
Cmdlet          Add-SqlLogin                                       21.0.17262 SqlServer
Cmdlet          Backup-ASDatabase                                  21.0.17262 SqlServer
Cmdlet          Backup-SqlDatabase                                 21.0.17262 SqlServer
                                        ...
Cmdlet          Test-SqlSmartAdmin                                 21.0.17262 SqlServer
Cmdlet          Write-SqlTableData                                 21.0.17262 SqlServer
Function        SQLSERVER:                                         21.0.17262 SqlServer
Alias           Decode-SqlName                                     21.0.17262 SqlServer
Alias           Encode-SqlName                                     21.0.17262 SqlServer

I tried installing an older version of the SqlServer module, as well as tried a different user account on my machine. Lots of reboots, new PS sessions, etc. Running Import-Module in verbose/debug mode doesn't throw any errors, it just imports only the function and aliases; none of the Cmdlets. The problem factor seems to be this particular Windows system, which is Windows 10 Pro 1803.

It is also worth noting that I'm only trying to use this module because the sqlps module that comes installed with SQL Server Management Studio stopped working on this machine. I don't know why that was the case; my guess was relating to a Windows or SSMS update, but in order to get to the point here where at least the SqlServer module installs without errors and warnings about clobbering, I removed that module from my $PSModulePath. Something else that broke seemingly at the same time was that my WSMan TrustedHosts list was reset (to blank), causing issues with PowerShell remoting that I had solved previously (this machine is not domain-joined).

How in the heck do I troubleshoot this?

NReilingh
  • 5,883

1 Answers1

4

The source of the problem seems to be a broken installation of .Net 4.7.2 that occasionally happens with installing the 1803 Windows 10 Update.

The only way I've managed to resolve this is with a Windows 10 Repair Install. This reinstalls all the core OS files and configuration but does not remove your Apps or data. But you should still make sure backup any important documents before doing it.

Others have found success with:

You may want to try these steps before doing the Repair Install of Windows. They didn't work for my situation.

ysalmi
  • 156