powershell - Import-DscResource 找不到包 cChoco

标签 powershell azure powershell-dsc

我正在尝试编写一个将发布到 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/

相关文章:

windows - 如何摆脱 Batch/Powershell 中的安全警告

node.js - Azure管道: Cannot download "https://github.com/sass/node-sass/releases/download/v4.13.0/win32-x64-83_binding.node"

html - HTTP 基本身份验证 - 仅密码,无用户名?

c# - 通过应用程序配置获取 KeyVault 值

powershell - 通过 Azure 资源管理器应用多个 DSC

powershell - 如何获取 Azure DSC 配置来读取名称为参数的自动化帐户变量?

powershell - PowerShell是否具有类似于Perl abbrev()函数的功能

Azure API 管理 - 如何通过 PowerShell 命令启用 HTTP/2?

powershell - 使用 PowerShell 将前导零添加到文件名