如何使用 powershell DSC 运行 批处理文件?

How to run a batch file using powershell DSC?

我需要 运行 file.bat 使用 DSC 资源。我能够成功执行 file.bat 的唯一方法是使用 Package 资源。但是我收到以下错误:

PowerShell DSC resource MSFT_PackageResource failed to execute Set-TargetResource functionality with error message: Package from Directory\To\MyFile\file.bat was installed, but the specified ProductId and/or Name does not match package details

我知道错误的意思,之前已经解决了。但是,批处理文件没有 productId 或名称。

我还能如何使用 DSC 运行 批处理文件?

我想把问题算作已回答。感谢@beatcracker 提供答案。

使用 Script resource 并在 SetScript 脚本块中使用

& your\batch\file\directory.yourBatchFile.bat optionalArguments

如果不行,试试

Invoke-Command -ScriptBlock {& your\batch\file\directory.yourBatchFile.bat optionalArguments}

:D