DSC Environment resource failing to see environment variable it has set

Welcome Forums DSC (Desired State Configuration) DSC Environment resource failing to see environment variable it has set

This topic contains 4 replies, has 3 voices, and was last updated by

1 year, 6 months ago.

  • Author
  • #63734

    Points: 4
    Rank: Member

    (cross-post from http://serverfault.com/questions/831295/dsc-environment-resource-failing-to-see-environment-variable-it-has-set)

    I'm using DSC to provision virtual machines. The VMs are setup to pull a DSC configuration from a pull server. All is well with this. However, I noticed that I am frequently seeing:

    Job {8B376B76-EDE7-11E6-80FC-3649808F2EC1} : 
    From LCM, message is 
        Completed processing test operation. The operation returned False.

    In the event logs. Using a useful tip I found here https://powershell.org/forums/topic/lcm-event-log-entries-for-different-configurationmode-settings/, I can see that an Environment variable resource is failing – despite the fact that the environment variable was created:

    VERBOSE: [TESTEZE-CDEUURA]: LCM:  [ Start  Resource ]  [[Environment]EZELOGS]
    VERBOSE: [TESTEZE-CDEUURA]: LCM:  [ Start  Test     ]  [[Environment]EZELOGS]
    VERBOSE: [TESTEZE-CDEUURA]:                            [[Environment]EZELOGS] (NOT FOUND) Environment variable 'EZELOGS'
    VERBOSE: [TESTEZE-CDEUURA]: LCM:  [ End    Test     ]  [[Environment]EZELOGS] False in 0.0190 seconds.
    VERBOSE: [TESTEZE-CDEUURA]: LCM:  [ End    Resource ]  [[Environment]EZELOGS]

    (I know the environment variable was created because I can see it in the environment variables dialog).

    If I manually reboot the machine, the consistency check then passes.

    My LCM configuration is set to RebootIfNeeded=$true and ActionAfterReboot = 'ContinueConfiguration'.

    The resource definition is this:

    Environment EZELOGS {
        Name = "EZELOGS"
        Value = "C:\Logs"
        Ensure = "Present"

    The LCM is creating the variable, but it does not seem to be able to see the variable, and ends up cycling the configuration every 30mins. Any pointers?

    Environment is Windows Server 2012 R2 (I know, I know...), with Powershell 5, WMF 5.0 (from KB3134758)

  • #63778

    Points: 101
    Helping Hand
    Rank: Participant

    What happens if you close the PS window you are running the config and and re-open it? I believe (could be wrong) that your current PowerShell session is not aware of the new environment change until it is relaunched.

    • #63811

      Points: 4
      Rank: Member

      I would be very surprised if it was the case, because I wanted the commands from the referenced tip to report what the *LCM* thinks the state of the system is, and not to report on my session..

      In any case, I executed the commands _after_ the event log reported the warning. So this is a completely new window _after_ the resources had been fulfilled by the LCM. (so I would expect my session to actually see the variables – unfortunately I had already rebooted the VM)

    • #63817

      Points: 4
      Rank: Member

      I wanted to verify this for certain, so I ran up a new VM and applied the configuration without a reboot and yes, it is as I expected: a new powershell session can see the edits to


      , but when I run the actual configuration check commands, the LCM cannot see the system variable.

  • #77083

    Points: 32
    Rank: Member

    Just for documentation...
    – there are 3 scopes for environment variables: user, machine and process
    – each time a process start, machine and user scopes are copied in process scope
    – with Environment DSC resource, LCM modifies machine scope but checks process scope, so the LCM has to restart to 'see' modification (a reboot does the trick)
    – xEnvironment from xPSDesiredStateConfiguration, since version, does the job (see https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/172)

The topic ‘DSC Environment resource failing to see environment variable it has set’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort