【问题标题】:Import-DscResource cannot find the package cChocoImport-DscResource 找不到包 cChoco
【发布时间】:2017-02-17 01:25:09
【问题描述】:

我正在尝试编写将发布到 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'.

【问题讨论】:

  • 机器上是否安装了模块 cChoco?错误消息非常清楚地说明了问题所在。
  • 我以为 Import-DscResource 会导入它,但后来我发现我可以使用 Install-Module 并安装模块。感谢您指出。

标签: powershell azure powershell-dsc


【解决方案1】:

您可以手动(通过将其放在 zip 文件的 a 子文件夹中)或使用 Publish-AzureVMDSCConfiguration cmdlet 将模块捆绑在 DSC 包中。如果模块安装在您运行 cmdlet 的计算机上,它将查看您 PS1 文件中的所有导入模块语句并为您打包它们 - 一旦打包,当您在目标计算机上运行脚本时,模块(s ) 也会自动安装...

【讨论】:

  • 我在一篇关于 DSC 的故障排除博客文章中发现了您所说的内容。我注意到 cChoco 是包装好的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-27
  • 2020-03-01
  • 1970-01-01
  • 2012-06-19
  • 2011-09-18
  • 2020-09-19
  • 2021-12-03
相关资源
最近更新 更多