0

I have installed SqlServer moduled with Install-Module -Name SqlServer -Repository PSGallery -Verbose command. PS says that it was successfuly.

But when I'm runneng import-module I only see 3 items imported from this module:

PS >import-module sqlserver -erroraction stop -verbose
VERBOSE: Loading module from path 'C:\Program 
Files\WindowsPowerShell\Modules\sqlserver\21.0.17240\sqlserver.psd1'.
VERBOSE: Populating RepositorySourceLocation property for module sqlserver.
VERBOSE: Loading module from path 'C:\Program 
Files\WindowsPowerShell\Modules\sqlserver\21.0.17240\SqlServer.psm1'.
VERBOSE: Exporting function 'SQLSERVER:'.
VERBOSE: Exporting alias 'Encode-SqlName'.
VERBOSE: Exporting alias 'Decode-SqlName'.
VERBOSE: Importing function 'SQLSERVER:'.
VERBOSE: Importing alias 'Decode-SqlName'.
VERBOSE: Importing alias 'Encode-SqlName'.

Question: how to get all the commands (like Invoike-Sqlcmd and other) from SqlServer working?

PS Version

Name                           Value                                                                                                                                                                                                 
----                           -----                                                                                                                                                                                                 
PSVersion                      5.1.16299.251                                                                                                                                                                                         
PSEdition                      Desktop                                                                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                               
BuildVersion                   10.0.16299.251                                                                                                                                                                                        
CLRVersion                     4.0.30319.42000                                                                                                                                                                                       
WSManStackVersion              3.0                                                                                                                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                   
SerializationVersion           1.1.0.1                                                                                                                                                                                               

UPDATE:

Running Get-Command -Module SqlServer | Measure gives even after force reinstall with Install-Module SqlServer -Force:

PS H:\> Get-Command -Module SqlServer | Measure

Count    : 3
Average  :
Sum      :
Maximum  :
Minimum  :
Property :

Checked event log. Found bunch of Information records, when importing the SqlServer module like this:

Context Information: 
    DetailSequence=1
    DetailTotal=1

    SequenceNumber=17

    UserId=DOMAIN/User
    HostName=ConsoleHost
    HostVersion=5.1.16299.251
    HostId=GUID
    HostApplication=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    EngineVersion=5.1.16299.251
    RunspaceId=GUID
    PipelineId=6
    ScriptName=C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.0.17240\SqlServer.psm1
    CommandLine=        Add-Type -Path $binaryPath


Details: 
CommandInvocation(Add-Type): "Add-Type"
ParameterBinding(Add-Type): name="Path"; value="C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.0.17240\Microsoft.SqlServer.Dmf.dll"
Oleg Oshkoderov
  • 500
  • 1
  • 4
  • 17
  • 1
    If you run ```Get-Command -Module SqlServer | Measure```, you should get about 98-commands. What do you get? You can try to re-install the module (```Install-Module SqlServer -Force```) Then try to load it again. I pulled the module down today, and I'm not having the problem you described. – Adam May 04 '18 at 15:14
  • Only 3.The command output in the question update. End even after force reinstall, output remains the same. What could be the reason? – Oleg Oshkoderov May 07 '18 at 06:58

1 Answers1

0

Hmm. Okay do this...

  1. Find all your various module folders -- you can use the following to do this:

    $env:PSModulePath.Split(';')

  2. Removing the "sqlserver" folder from each directory, if it exists.

  3. Re-import the module.

    Install-Module -Name SqlServer -AllowClobber

Steps-1 and -2 make sure there are no mangled SqlServer module installations lurking anywhere. Step-3 gives us a fresh pull of the module.

The only thing I can think of. Maybe there is a mangled module installed somewhere. It isn't getting overwritten during re-install, but it's accidentally getting loaded.

Adam
  • 3,891
  • 3
  • 19
  • 42
  • Thank you for answer. Unfortunately didn't helped. The only folder I have found was: `C:\Program Files\WindowsPowerShell\Modules\SqlServer\` and after reistall it was recreated. And it still exports only 3 items: that are defined in `SqlServerPostScript.ps1`. But it looks like PS ignores items that defined in `CmdletsToExport` property in `SqlServer.psd1` file. Event though `Import-Module -Verbose -Name SqlServer` shows that it loads it. BTW. Last command shows that it loads from `C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.0.17240\` path. – Oleg Oshkoderov May 07 '18 at 14:24
  • Rats! What edition/version OS you running? I'm testing this on a Windows 10 64-bit machine. – Adam May 07 '18 at 15:03
  • It's Windows 10 Pro, 64-bit. – Oleg Oshkoderov May 08 '18 at 06:01
  • Man, I’m drawing a blank. I tried to recreate this a few different ways, but can’t. Anything unusual about your environment? – Adam May 11 '18 at 00:32
  • Not of anything I'm aware of. I'm developer, so I have VS, .Net Core and SQL Server installed. Also this question is confituation of https://stackoverflow.com/questions/49359773/backup-sqldatabase-is-not-recognized as I realized bigger issue. – Oleg Oshkoderov May 15 '18 at 07:39