PowerShell / PSDscResources

MIT License
129 stars 53 forks source link

Enviroment: Enviroment sets nonExpaned path #180

Open mh185277 opened 4 years ago

mh185277 commented 4 years ago

Details of the scenario you tried and the problem that is occurring

Environment EnvironmentPath {
    Ensure = "Present"
    Path = $true
    Name = "Path"
    Value = "C:\myPath\forExample"
}

Verbose logs showing the problem

The $env:path is changed from C:\Windows\system32;C:\Windows; to %SystemRoot%\system32;%SystemRoot%; (Custom path is added correctly, but problem is with changing C:\Windows to %SystemRoot%

Suggested solution to the issue

n/a

The DSC configuration that is used to reproduce the issue (as detailed as possible)

# insert configuration here

Configuration Config { Import-DscResource -ModuleName PSDesiredStateConfiguration

Node $NodeName
{
    ScEnvironment EnvironmentConfiguration
    {
    }
}

}

The operating system the target node is running

OsName : Microsoft Windows 10 Enterprise LTSC OsOperatingSystemSKU : 125 OsArchitecture : 64-bit WindowsVersion : 1809 WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434 OsLanguage : en-US OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.17763.771 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.771 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

latest

PlagueHO commented 4 years ago

Hi @MartinNcr ,

Sorry about the delay in getting back to you:

I've just noticed that the resource your config is using the Environment resource in the inbox PSDesiredStateConfiguration resource module. Those are the ones that come with Windows and are much older than this one. Can you instead use the Environment resource in this module: PSDscResources

PSDscResources is a replacement for the Inbox resources. It is supported. There is also a community version of this module (xPSDesiredStateConfiguration) that would also work but may differ in function from the PSDscResources module.

Ryfteh commented 4 years ago

This still isn't working, even in the PSDscResources module.

If you look under: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment at the Path variable before it gets set by the resource, it will be of type REG_EXPAND_SZ, but afterwards it becomes a REG_SZ

PlagueHO commented 4 years ago

Hi @Ryfteh - ah, I this I see part of the problem:

We are using Set-ItemProperty (see this line) to set registry key value. If the registry key does not exist then this gets created as a REG_SZ rather than a REG_EXPAND_SZ.

So this works fine if updating the Path variable as this is already set to a REG_EXPAND_SZ, but any other path type that is newly created by the resource will create this as a REG_SZ.

However, this doesn't explain the following behaviors that you're seeing:

  1. Existing REG_EXPAND_SZ being replaced by a REG_SZ.
  2. Why the Path string is being expanded when written to the registry as this isn't something the resource does (it is written as is).

Is there any more information that can be provided, such as an example config that demonstrates this problem? If I can replicate then I can trace it back.

Ryfteh commented 4 years ago

Sorry for the minimal information provided. I’ll provide system info and give an example when I sit down at my computer next.

Ryfteh commented 4 years ago

That's my fault, I seen one error and thought it was another. My registry property type starts as a REG_SZ, so this doesn't cause it to change.

I am still having an issue, but I don't think it still pertains to this topic, so I'll create a seperate issue to track it.