powershell - DSC,将ps1文件编译成MOF

标签 powershell dsc

我正在尝试通过 DSC 配置目标节点。
我创建了一个带有虚拟配置的 .ps1 文件;你可以在下面看到它;这只是您在 DSC 站点中找到的首批示例之一。
现在我想把它编译成 .mof 文件。
我已经执行了:

PS C:\var\DSC\Configurations> . .\localhost.ps1

但它什么也不做。 mof 文件不会出现,也不会抛出任何错误消息。
我错过了什么?
Configuration FileResourceDemo
{
Node "localhost"
{
    File DirectoryCopy
    {
        Ensure = "Present"  # You can also set Ensure to "Absent"
        Type = "Directory" # Default is "File".
        Recurse = $true # Ensure presence of subdirectories, too
        SourcePath = "C:\Users\Public\Documents\DSCDemo\DemoSource"
        DestinationPath = "C:\Users\Public\Documents\DSCDemo\DemoDestination"    
    }

    Log AfterDirectoryCopy
    {
        # The message below gets written to the Microsoft-Windows-Desired  State Configuration/Analytic log
        Message = "Finished running the file resource with ID DirectoryCopy"
        DependsOn = "[File]DirectoryCopy" # This means run "DirectoryCopy"  first.
    }
}
} 

最佳答案

Configuration关键字只定义了配置(把它想象成 function 关键字)。之后你必须执行它,通过像函数一样调用它(它甚至可以有参数,但你的没有)。

所以如果,在你的 .ps1 的末尾您添加的文件:

FileResourceDemo

它会在定义后立即执行。

或者,由于您是根据您的问题点源文件,您可以通过键入 FileResourceDemo 直接以交互方式执行它。进入提示。它甚至应该是tab-complete。

关于powershell - DSC,将ps1文件编译成MOF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40661214/

相关文章:

oracle - 无法在 Powershell 中使用加载的 Oracle.ManagedDataAccess 程序集

powershell - 当保存脚本的文件夹名称包含空格时从任务计划程序运行 Powershell 脚本

xml - 如何使用 PowerShell 向 web.config 添加一个部分?

windows - 自动化远程桌面连接

Powershell DSC xChrome 示例在 AzureVM 上失败

powershell - 重新启动后重新获取DSC后台作业

powershell - 使用PowerShell在目录中获取文件名

powershell - DSC 文件资源文件不复制 PDB 文件

Powershell DSC - 使用 cChocoInstaller installChoco 在首次运行后显示不合规