如何debuggingPowershell所需的状态configuration不生成MOF文件?

我正在关注MSDN上的最基本的例子 ,我没有得到它的工作。 我有我的configuration定义如下:

Configuration MyWebConfig { Param($ComputerName) Node $ComputerName { WindowsFeature MyRoleExample { Ensure = "Present" Name = "Web-Server" } } } 

我试图用C:\Scripts> .\IisWithCompressionConfig.ps1 -ComputerName "localhost" -Outputpath C:\Scripts\localhost生成MOF C:\Scripts> .\IisWithCompressionConfig.ps1 -ComputerName "localhost" -Outputpath C:\Scripts\localhost (和其他命令行变体)。 我没有得到任何文件输出,没有错误报告(退出状态码也是0)。 我试过一个没有$ComputerNamevariables的版本(而不是“本地主机”硬编码),仍然没有。 是的,我正在用提升的提示符运行这个。

我确定我正在运行PowerShell 4.0:

 C:\Scripts> $PSVersionTable Name Value ---- ----- PSVersion 4.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.34003 BuildVersion 6.3.9600.16394 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} PSRemotingProtocolVersion 2.2 

任何想法我错过了什么?

使用DSC,我将源configuration定义input到当前会话中,然后调用它。

 # dot source will load PS1 into current session . .\IisWithCompressionConfig.ps1 # Then call the config MyWebConfig -ComputerName "localhost" 

configuration与函数非常相似,即你想调用MyWebConfig (config)而不是IisWithCompressionConfig (file)。 实际上,所定义的DSC将在Function: PSDrive中。 尝试运行之前和之后,您点击源PS1。 之前,你应该看不到任何结果,之后,你应该在Function: PSDrive中看到MyWebConfig

 Get-ChildItem Function:* | Where-Object { $_.CommandType -eq 'Configuration' } 

在提供的TechNet示例中,他们正在使用ISE。 在第4步中,他们正在定义(而不是源)当前PS会话中的MyWebConfigconfiguration。 这在function上等同于点源PS1文件。 在第6步之后,他们调用MyWebConfig ,它生成了MOF。