【发布时间】:2022-04-22 03:30:20
【问题描述】:
我在 Windows 10 上的 dsc 配置有问题。我必须定义一个脚本块,因为考虑到它需要服务器 sku,我无法使用 dsc 安装 WindowsIIS。以下代码是绕过它的方法示例(排序),但由于某种原因,我无法从脚本块调用我的模块或函数。看看:
Configuration update-settings
{
$hostname = $env:COMPUTERNAME
Node $hostname
{
Script whatever
{
GetScript = { return @{'Result' = 'something'} }
TestScript = { return $false }
# problem is here:
SetScript = { run-myfunction -args something }
}
}
}
我在别处有一个 psm1 文件,即使我在我的 dsc 中执行 Import-Module C:\MyFolder\PSModules\run-myfunctions.psm1 -force,它仍然给我以下错误:
PowerShell DSC resource MSFT_ScriptResource failed to execute Set-TargetResource functionality with error message: The term 'run-myfunction' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName : DESKTOPofMe
The SendConfigurationApply function did not succeed.
+ CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName : DESKTOPofMe
仅供参考,我确实正确运行并导出了我的 powershell 模块,并且可以在命令行上使用run-myfunction 或run-myfunction2 等访问它们。
任何帮助将不胜感激,谢谢:)
【问题讨论】:
-
Import-Modulecmdlet 不会抛出任何错误吗? -
不,根本没有:)
-
我认为您遇到的问题与 DSC 脚本资源有关,该资源在抛出到 Invoke-Command 的脚本块中执行脚本,您可以通过检查 C:\Windows\ 的 psm1 来查看它是如何执行的SysWOW64\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\DSCResources\MSFT_ScriptResource 在你的机器上。你也可以检查这个问题,因为它有点相同的问题:stackoverflow.com/questions/14441800/…
标签: powershell dsc