PowerShell Import-Module SqlServer Could not load PSSnapins.dll

0

Trying to Import SQL Server module to use Invoke-Sqlcmd and whether in raw PowerShell ISE (as Administrator and non-Admin) or via SSMS I get the same error and wondering if someone could help please?

The version I am using is an unzipped nupkg of sqlserver.21.1.18230 (the latest release) and the DLL's are in the right location (C:\Program Files\WindowsPowerShell\Modules). The DLL's are not showing as Blocked in the Properties. Security is showing "Full Control" on the DLL in the Properties.

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select PSChildName, Version, Release

##Get PowerShell version
$PSVersionTable

$Env:PSModulePath
#Get-PSRepository

Get-ExecutionPolicy -List

[Environment]::Is64BitProcess

Import-Module SqlServer

The Import-Module is failing with the following results (after the error a raft of other DLL's from the SqlServer.psm1 script are listed also erroring)

PSChildName                      Version        Release
-----------                      -------        -------
v2.0.50727                       2.0.50727.4927        
v3.0                             3.0.30729.4926        
Windows Communication Foundation 3.0.4506.4926         
Windows Presentation Foundation  3.0.6920.4902         
v3.5                             3.5.30729.4926        
Client                           4.8.03752      528040 
Full                             4.8.03752      528040 
Client                           4.0.0.0  

C:\Users\app-itsme\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\windows\system32\WindowsPowerShell\v1.0\Modules

Import-Module : Could not load file or assembly 'file:///C:\Program Files\WindowsPowerShell\Modules\SqlServer\Microsoft.SqlServer.Management.PSSnapins.dll' or one of its dependencies. Operation is not 
supported. (Exception from HRESULT: 0x80131515)
At C:\Program Files\WindowsPowerShell\Modules\SqlServer\SqlServer.psm1:61 char:25
+ ...       $binaryModule = Import-Module -Name $binaryModulePath -PassThru
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
 
The variable '$binaryModule' cannot be retrieved because it has not been set.
At C:\Program Files\WindowsPowerShell\Modules\SqlServer\SqlServer.psm1:63 char:29
+         $importedModules += $binaryModule
+                             ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (binaryModule:String) [], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined

Any help appreciated

Thank you

sql-server
powershell
asked on Stack Overflow Dec 17, 2020 by wonderbison

1 Answer

0

The issue was still around permissions and installation. Installation seemed to have to be at non-admin and then Install-Module at non-admin. It was then available as admin. Also the Powershell admin doesnt have internet access something that Powershell assumes always exists which added to the woes of other solutions being attempted. Had to set proxy firewall etc Thanks

answered on Stack Overflow Dec 18, 2020 by wonderbison

User contributions licensed under CC BY-SA 3.0