我正在尝试编写一个将发布到 Azure 虚拟机中的 DSC 脚本。到目前为止,我已经能够完成一些基本的事情,例如启用 Windows 功能和创建目录。但现在我想在azure虚拟机上安装chocolatey。这是我的脚本
configuration IIsAspNetInstall
{
Import-DscResource -ModuleName cChoco
node "localhost"
{
WindowsFeature IIS
{
Ensure="present"
Name="web-server"
}
WindowsFeature InstallDotNet45
{
Name = "Web-Asp-Net45"
Ensure = "Present"
}
WindowsFeature InstallIISConsole
{
Name = "Web-Mgmt-Console"
Ensure = "Present"
}
File WebsiteFolderCreate
{
Ensure = "Present"
Type = "Directory"
DestinationPath = "C:\inetpub\wwwroot\AdventureWorks"
Force = $true
}
cChocoInstaller installChoco
{
InstallDir = "C:\choco"
}
}
}
在我的本地计算机上,我使用 PowerShell 5.0,在 ISE 内,我在 Import-DscResource
下看到红色波浪线,表示找不到 moduleName cChoco。我知道它是一个关键字,并且应该在配置部分中有效。当我执行Publish-AzureVMDscConfiguration
时,我收到解析错误
+ Import-DscResource -ModuleName cChoco
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Could not find the module 'cChoco'.
最佳答案
您可以手动(通过将其放入 zip 文件的子文件夹中)或使用 Publish-AzureVMDSCConfiguration cmdlet 将模块捆绑到 DSC 包中。如果模块安装在运行 cmdlet 的计算机上,它将查看 PS1 文件中的所有导入模块语句并为您打包 - 一旦打包,当您在目标计算机上运行脚本时,模块(s )也会自动安装...
关于powershell - Import-DscResource 找不到包 cChoco,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39927510/