【问题标题】:PowerShell Import-Module SqlServer Could not load PSSnapins.dllPowerShell 导入模块 SqlServer 无法加载 PSSnapins.dll
【发布时间】:2020-12-18 19:26:27
【问题描述】:

尝试导入 SQL Server 模块以使用 Invoke-Sqlcmd,无论是在原始 PowerShell ISE(作为管理员和非管理员)还是通过 SSMS,我都会遇到同样的错误,想知道是否有人可以帮忙?

我使用的版本是 sqlserver.21.1.18230(最新版本)的解压缩 nupkg,并且 DLL 位于正确的位置(C:\Program Files\WindowsPowerShell\Modules)。 DLL 在属性中未显示为已阻止。安全性在属性中显示对 DLL 的“完全控制”。

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

Import-Module 失败并出现以下结果(在出现错误后,来自 SqlServer.psm1 脚本的大量其他 DLL 也列出了错误)

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

任何帮助表示赞赏

谢谢

【问题讨论】:

    标签: sql-server powershell


    【解决方案1】:

    问题仍然在于权限和安装。安装似乎必须在非管理员下进行,然后在非管理员下进行安装模块。然后它可以作为管理员使用。 此外,Powershell 管理员没有 Internet 访问权限,Powershell 假设始终存在的东西增加了正在尝试的其他解决方案的困境。必须设置代理防火墙等 谢谢

    【讨论】:

      猜你喜欢
      • 2017-09-22
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多