Invalid MOF generated if File resource used with contents that contain ModuleVersion=xxx string
A simple DSC File resource usage:
Configuration CopyCustomResourceProviders {
Import-DSCResource -ModuleName @{ModuleName="PSDesiredStateConfiguration"; ModuleVersion="1.1"}
Node $nodeName {
File test {
DestinationPath = "$pshome\Modules\empty"
Contents="ModuleVersion='1.2'"
}
}
}
This generates invalid MOF content:
instance of MSFT_FileDirectoryConfiguration as $MSFT_FileDirectoryConfiguration1ref
{
ResourceID = "[File]test";
Contents = "ModuleVersion='1.2'";
DestinationPath = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\Modules\\empty";
ModuleName = "PSDesiredStateConfiguration";
SourceInfo = "C:\\Source\\CoreDev\\Trunk\\Provisioning\\CopyCustomResourceProviders.ps1::34::4::File";
ConfigurationName = "CopyCustomResourceProviders";
};
And the following error occurs on the command line when trying to push this configuration:
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer WSDING037 with user sid S-1-5-21-441617589-1049517295-4151535418-2019.
VERBOSE: [TESTEZE-0VPMUS0]: LCM: [ Start Set ]
VERBOSE: [TESTEZE-0VPMUS0]: LCM: [ End Set ]
Could not find mandatory property ModuleVersion. Add this property and try again.
+ CategoryInfo : ObjectNotFound: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 6
+ PSComputerName : TESTEZE-0VPMUS0
The error disappears if I manually add
ModuleVersion = "1.1";
to the MOF file.
Why do I need to have this content pushed to remote server? I'm actually trying to push out a set of custom Powershell modules for use in later scripts and ModuleVersion=... is a fairly standard string in PS land.
For now, work around is to not use DSC to push PS modules. Instead, I'm using
Invoke-Command -ComputerName $nodeName -ScriptBlock {
Install-PackageProvider -Name NuGet -Force -Scope AllUsers
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Find-DscResource -ModuleName "cChoco" | Install-Module
}
@pmcevoy It might be better to submit above on PowerShell UserVoice instead of the PowerShell documentation repository unless you want this addressed via an addition to the documentation.
I can repro this on 5.1. The issue manifests when Contents contains ModuleVersion= and ModuleVersion from Import-DscResource specifies a ModuleVersion. Changing either of those allows this configuration to work as expected. Tagging for PG review.
This is a bug that needs to be fixed. We should not document the buggy behavior.