DSC icon indicating copy to clipboard operation
DSC copied to clipboard

Error while testing the `winps_script.dsc.yaml` example

Open FlippingBinary opened this issue 6 months ago • 5 comments

Prerequisites

  • [x] Write a descriptive title.
  • [x] Make sure you are able to repro it on the latest version
  • [x] Search the existing issues.

Summary

I am getting an error "You cannot call a method on a null-valued express" when trying the winps_script.dsc.yaml example with the stable release, or a manifest description: Error warning and error with the preview release. If I set the Process ExecutionPolicy to Bypass, the preview release gives the same error as the stable release.

I'm including trace outputs from both the stable and preview releases of the CLI to show the differences in impact the Process ExecutionPolicy has on the two different releases. I installed them with winget install --id Microsoft.DSC -e and winget install --id Microsoft.DSC.Preview -e (one at a time with the other uninstalled), so those are the names I use in the filenames of the attached trace output files. In each case, I had the CurrentUser and LocalMachine ExecutionPolicy set to Bypass (temporarily) and either set the Process ExecutionPolicy to Undefined or Bypass to show the impact that has on both releases.

Each trace output was generated with this command: dsc -l trace config test --file .\winps_script.dsc.yaml.

Microsoft.DSC.Preview-Bypass.txt Microsoft.DSC.Preview-Undefined.txt Microsoft.DSC-Bypass.txt Microsoft.DSC-Undefined.txt

Steps to reproduce

  1. Save a local copy of the example script.
  2. Call test or any of the other methods on it. e.g. dsc config test --file .\winps_script.dsc.yaml

Expected behavior

No errors

Actual behavior

An error: `You cannot call a method on a null-valued expression.`

Error details

2025-05-17T18:30:40.366999Z ERROR PID 2420: Exception: You cannot call a method on a null-valued expression.
2025-05-17T18:30:40.386900Z ERROR Command: Resource 'powershell' [exit code 1] manifest description: Error

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.1
PSEdition                      Core
GitCommitId                    7.5.1
OS                             Microsoft Windows 10.0.26100
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.1.0-preview.1 (or dsc 3.0.2)

Visuals

No response

FlippingBinary avatar May 17 '25 18:05 FlippingBinary

@FlippingBinary, the actual error messages is displayed in the trace logs:

2025-05-17T17:01:55.768361Z TRACE dsc_lib::dscresources::command_resource: 890: PID 12412: The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig"

Using the Microsoft.Windows/WindowsPowerShell still requires Windows Remote Management enabled. Can you try running winrm quickconfig and run the example once again?

Gijsreyn avatar May 18 '25 11:05 Gijsreyn

Ahh, that was it, I think. Thank you, @Gijsreyn. I was just about to update this issue to mention that none of the examples using Microsoft.Windows/WindowsPowerShell were working when I saw your comment. Now the stable release just throws the warning/error that appears above the result of the task:

> dsc config get --file .\winps_script.dsc.yaml
2025-05-18T14:58:29.350432Z  WARN Command: Resource 'powershell' [exit code 1] manifest description: Error
metadata:
  Microsoft.DSC:
    version: 3.0.0
    operation: get
    executionType: actual
    startDatetime: 2025-05-18T10:58:28.424057100-04:00
    endDatetime: 2025-05-18T10:58:31.640612100-04:00
    duration: PT3.216555S
    securityContext: elevated
results:
- metadata:
    Microsoft.DSC:
      duration: PT2.2893746S
  name: Run WinPS script
  type: Microsoft.Windows/WindowsPowerShell
  result:
    actualState:
      result:
      - name: Run script
        type: PSDesiredStateConfiguration/Script
        properties:
          GetScript: null
          PSComputerName: localhost
          TestScript: null
          ResourceId: null
          PsDscRunAsCredential: null
          Credential: null
          SetScript: null
          ConfigurationName: null
          DependsOn: null
          SourceInfo: null
          ModuleVersion: '1.1'
          ModuleName: PSDesiredStateConfiguration
          Result: get
messages: []
hadErrors: false

That warning/error goes away if I use Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force in the same session before using dsc and the preview release won't work without it.

FlippingBinary avatar May 18 '25 15:05 FlippingBinary

I've just hit up a small PR for more clarification. Still curious about the warning message. Can you dump in the trace log with --trace-level trace on? If you have sensitive data, you can trim the result to the last five lines. @michaeltlombardi, probably you're pretty busy with Microsoft Build, but if you've some time left, can you review the pull request please? Thanks!

Gijsreyn avatar May 18 '25 16:05 Gijsreyn

Yeah, I'll share four again to show the difference between stable and preview both with and without the bypass execution policy.

Microsoft.DSC.Preview-Bypass.txt Microsoft.DSC.Preview-Undefined.txt Microsoft.DSC-Bypass.txt Microsoft.DSC-Undefined.txt

FlippingBinary avatar May 18 '25 19:05 FlippingBinary

@FlippingBinary, just hit up a PR for the warning also. When you used v3.0.2, the #715 wasn't released yet. In the preview release, it was. However, the WMI adapter is called when the first list operation takes place. That's why you still required to use ByPass. With the upcoming PR, you wouldn't have to pass any executionpolicy and the warning should go away. Nice catch!

Gijsreyn avatar May 19 '25 04:05 Gijsreyn

Thank you @Gijsreyn for your responses to this -- Thank you @FlippingBinary for reporting the issue!

theJasonHelmick avatar May 21 '25 15:05 theJasonHelmick