1

On the current version of WMF5, I try and invoke a DSC resource using Invoke-DSCResource like so:

$destinationPath="$env:SystemDrive\DirectAccess.txt"
$fileContents="This file is create by Invoke-DscResource"
$result = Invoke-DscResource -Name File -Method Test -Property @{
DestinationPath=$destinationPath
Contents=$fileContents } -Verbose
$result | fl * 

However, I'm asked for a module name for the "File" resource.

Doing Get-DscResource File lists the dsc resource, but the "module" property is empty. How can I figure out which module to pass Invoke-DscResource? Where (in what module) does the "File" resource really live?

Trondh
  • 4,201
  • 24
  • 27

2 Answers2

1

PSDesiredStateConfiguration was the correct module (can be seen in compiled mof when using the file resource). Apparently "File" is a weird DSC resource.

Trondh
  • 4,201
  • 24
  • 27
-1

The File resource in DSC is implemented as a WMI provider (the only resource that way) while the rest of the resources are implemented as PowerShell resources. Invoke-DscResource only works with PowerShell resources hence you will not be able to invoke it on File.

  • 1
    I'm afraid this is incorrect. `Invoke-DscResource` works with binary/WMI resources and PowerShell resources. It does not work with composite resources. As @Trondh found, File is a strange resource in that you must _infer_ the (required) module name is `PSDesiredStateConfiguration` whereas other resources will show it, through `Get-DscResource`. – briantist Nov 04 '17 at 16:22