簡體   English   中英

PowerShell 導入模塊 SqlServer 無法加載 PSSnapins.dll

[英]PowerShell Import-Module SqlServer Could not load PSSnapins.dll

嘗試導入 SQL 服務器模塊以使用 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

任何幫助表示贊賞

謝謝

問題仍然在於權限和安裝。 安裝似乎必須在非管理員下進行,然后在非管理員下進行安裝模塊。 然后它可以作為管理員使用。 此外,Powershell 管理員無法訪問互聯網,Powershell 假設始終存在,這增加了正在嘗試的其他解決方案的困境。 必須設置代理防火牆等謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM