PowerShell / DSC

This repo is for the DSC v3 project
MIT License
133 stars 22 forks source link

Windows PowerShell not running Set operation #445

Open mgreenegit opened 4 weeks ago

mgreenegit commented 4 weeks ago

Prerequisites

Summary

Running the Set operation with the File resource from the Windows PowerShell adapter is not resulting in a changed state.

Steps to reproduce

sudo pwsh {'{"DestinationPath": "c:\test.txt", "type": "File", "contents": "test", "type": "PSDesiredStateConfiguration/File"}' | dsc resource set -r 'Microsoft.Windows/WindowsPowerShell'}

Expected behavior

beforeState:
  result:
  - name: Microsoft.Windows/WindowsPowerShell
    type: PSDesiredStateConfiguration/File
    properties:
      ModifiedDate: null
      Type: null
      CreatedDate: null
      ResourceId: null
      PsDscRunAsCredential: null
      SourcePath: null
      Credential: null
      PSComputerName: localhost
      Checksum: null
      Contents: null
      DependsOn: null
      SourceInfo: null
      DestinationPath: c:\test.txt
      ConfigurationName: null
      Attributes: null
      Size: null
      ModuleVersion: '1.1'
      ModuleName: PSDesiredStateConfiguration
      Recurse: null
      Ensure: absent
      SubItems: null
      Force: null
      MatchSource: null
afterState:
    result:
  - name: Microsoft.Windows/WindowsPowerShell
    type: PSDesiredStateConfiguration/File
    properties:
      ModifiedDate: /Date(1712614476479)/                                                                                     Type: file                                                                                                              CreatedDate: /Date(1712614476477)/                                                                                      ResourceId: null                                                                                                        PsDscRunAsCredential: null                                                                                              SourcePath: null                                                                                                        Credential: null                                                                                                        PSComputerName: localhost                                                                                               Checksum: null
      Contents: null
      DependsOn: null
      SourceInfo: null
      DestinationPath: c:\test.txt
      ConfigurationName: null
      Attributes:
      - archive
      Size: 20
      ModuleVersion: '1.1'
      ModuleName: PSDesiredStateConfiguration
      Recurse: null
      Ensure: present
      SubItems: null
      Force: null
      MatchSource: null
changedProperties: [<should include data>]

Actual behavior

beforeState:
  result:
  - name: Microsoft.Windows/WindowsPowerShell
    type: PSDesiredStateConfiguration/File
    properties:
      ModifiedDate: null
      Type: null
      CreatedDate: null
      ResourceId: null
      PsDscRunAsCredential: null
      SourcePath: null
      Credential: null
      PSComputerName: localhost
      Checksum: null
      Contents: null
      DependsOn: null
      SourceInfo: null
      DestinationPath: c:\test.txt
      ConfigurationName: null
      Attributes: null
      Size: null
      ModuleVersion: '1.1'
      ModuleName: PSDesiredStateConfiguration
      Recurse: null
      Ensure: absent
      SubItems: null
      Force: null
      MatchSource: null
afterState:
  result:
  - name: Microsoft.Windows/WindowsPowerShell
    type: PSDesiredStateConfiguration/File
    properties:
      ModifiedDate: null
      Type: null
      CreatedDate: null
      ResourceId: null
      PsDscRunAsCredential: null
      SourcePath: null
      Credential: null
      PSComputerName: localhost
      Checksum: null
      Contents: null
      DependsOn: null
      SourceInfo: null
      DestinationPath: c:\test.txt
      ConfigurationName: null
      Attributes: null
      Size: null
      ModuleVersion: '1.1'
      ModuleName: PSDesiredStateConfiguration
      Recurse: null
      Ensure: absent
      SubItems: null
      Force: null
      MatchSource: null
changedProperties: []

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.26227
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

dsc 3.0.0-preview.8

Visuals

No response

mgreenegit commented 4 weeks ago

Same behavior when run in the context of a configuration

anmenaga commented 3 weeks ago

I have the same behavior locally. As far as I can tell from traces, the DSCv3/PSAdapter layer is doing everything right. It feels like the problem is somewhere in the resource or PSDesiredStateConfiguration module. If you can make the composite File resource work using Invoke-DscResource cmdlet, then the bug is in DSCv3/PSAdapter. Also, FYI: 1) in the traces I saw following message from the resource: The path cannot point to the root directory or to the root of a net share. 2) a better command syntax is moving resource type to set -r parameter: '{DestinationPath: c:\Temp\test.txt, type: File, contents: test, Ensure: present}' | dsc -l trace resource set -r 'PSDesiredStateConfiguration/File'

theJasonHelmick commented 2 weeks ago

I ran into the same that @mgreenegit has experienced with a config. I haven;t been successful with invoke-DscResource, but I think thats my mistake. Using Preview 7.


# Example configuration mixing native app resources with classic PS resources
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Use Windows PowerShell resources
  type: Microsoft.Windows/WindowsPowerShell
  properties:
    resources:
    - name: Default web page
      type: PSDesiredStateConfiguration/File
      properties:
        Ensure: Present
        Type: Directory
        SourcePath: c:\website\
        DestinationPath: 'c:\inetpub\wwwroot'
mgreenegit commented 2 weeks ago

@anmenaga fyi, confirmed the no repro when calling invoke-dsc directly

Invoke-DscResource -Name File -Method Set -ModuleName PSDesiredStateConfiguration -Property @{Ensure = 'Present'; DestinationPath = 'c:\test.txt'; Contents = 'Hello, World!'}

RebootRequired
--------------
False
mgreenegit commented 2 weeks ago
  1. a better command syntax is moving resource type to set -r parameter: '{DestinationPath: c:\Temp\test.txt, type: File, contents: test, Ensure: present}' | dsc -l trace resource set -r 'PSDesiredStateConfiguration/File'

Please note, this is a config set not a resource set