【发布时间】: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