我在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-Module
,您必须指定包含模块的文件夹的路径,而不是.psm1
文件的路径。因此,在您的情况下:
Import-Module C:\MyFolder\PSModules