【发布时间】:2021-11-21 10:04:26
【问题描述】:
我正在尝试通过 DSC 安装 SqlServer,但我一直遇到此错误
Exception calling "NewScriptBlock" with "1" argument(s): "At line:10 char:5
+ Import-DscResource -ModuleName 'SqlServerDsc'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Could not find the module 'SqlServerDsc'.
At line:438 char:9
+ SqlSetup 'InstallDefaultInstance'
+ ~~~~~~~~
我的 DSC 配置 sn-p 是这样的
Configuration InstallSoftware
{
param
(
$ComputerNames
)
Import-DSCResource -ModuleName PSDesiredStateConfiguration
Import-DSCResource -Module SqlServerDsc
Node $ComputerNames
{
WindowsFeature 'NetFramework45'
{
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
SqlSetup 'SqlInstall'
{
InstanceName = 'localhost\mssql2019'
Features = 'SQLENGINE'
Action = 'Install';
SourcePath = 'C:\SQL2019'
SQLSysAdminAccounts = @('Administrators')
DependsOn = '[WindowsFeature]NetFramework45'
}
}
InstallSoftware
我很肯定 SqlServer 已经安装在远程服务器上。
- Get-DscResource -Module SqlServerDsc 返回资源列表
- 并且该文件夹存在于 C:\Program Files\WindowsPowerShell\Modules\SqlServerDsc
非常感谢任何反馈/建议。 非常感谢您的宝贵时间。
【问题讨论】:
-
它可能在那里,但它可能无法使用。
Test-ModuleManifest -Path "C:\Program Files\WindowsPowerShell\Modules\SqlServerDsc\SqlServerDsc.psd1"(或适当的路径)报告什么? -
@AlwaysLearning 它怎么可能不可用?太奇怪了。我运行了 Test-ModuleManifest,我注意到 ExportedCommand 是空的。
PS C:\Windows\system32> Test-ModuleManifest -Path "C:\Program Files\WindowsPowerShell\Modules\SqlServerDsc\15.2.0\SqlSer verDsc.psd1" ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 15.2.0 SqlServerDsc -
Test-ModuleManifest 允许您检查格式错误的模块清单,例如不正确的声明或版本号不匹配,其中任何一个都可能产生“找不到模块 'SqlServerDsc'”错误消息。您也可以尝试使用
-Force参数重新安装模块,以确保没有丢失文件和/或损坏的文件系统 ACL。 -
感谢您的回复@AlwaysLearning!我通过在 Azure Devops 模块中添加模块来实现它
标签: sql-server powershell importerror dsc powershell-dsc