Skip to content

Commit cee5ed6

Browse files
Merge pull request #365 from pkotov87/main
Change [System.Environment]::SetEnvironmentVariable() to Set-ItemProperty
2 parents 28a60d8 + 9e5aa9e commit cee5ed6

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def munge_psmodulepath(resource)
773773
<<~MUNGE_PSMODULEPATH.strip
774774
$UnmungedPSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
775775
$MungedPSModulePath = $env:PSModulePath + ';#{vendor_path}'
776-
[System.Environment]::SetEnvironmentVariable('PSModulePath', $MungedPSModulePath, [System.EnvironmentVariableTarget]::Machine)
776+
Set-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment' -Name 'PSModulePath' -Value $MungedPSModulePath
777777
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
778778
MUNGE_PSMODULEPATH
779779
end

lib/puppet/provider/dsc_base_provider/invoke_dsc_resource_postscript.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Try {
66
} Finally {
77
If (![string]::IsNullOrEmpty($UnmungedPSModulePath)) {
88
# Reset the PSModulePath
9-
[System.Environment]::SetEnvironmentVariable('PSModulePath', $UnmungedPSModulePath, [System.EnvironmentVariableTarget]::Machine)
9+
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name 'PSModulePath' -Value $UnmungedPSModulePath
1010
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath', 'machine')
1111
}
1212
}

spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@
15291529
end
15301530

15311531
it 'updates the system PSModulePath to $MungedPSModulePath' do
1532-
expect(result).to match(/SetEnvironmentVariable\('PSModulePath', \$MungedPSModulePath/)
1532+
expect(result).to match(/-Name 'PSModulePath' -Value \$MungedPSModulePath/)
15331533
end
15341534

15351535
it 'sets the process level PSModulePath to the modified system PSModulePath' do

0 commit comments

Comments
 (0)