Skip to content

Commit 8f0646a

Browse files
pkotov87Paul Kotov
authored andcommitted
pkotov87 - change System.Environment]::SetEnvironmentVariable() to Set-ItemProperty
1 parent 22d50f0 commit 8f0646a

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Try {
66
} Finally {
77
If (![string]::IsNullOrEmpty($UnmungedPSModulePath)) {
88
# Reset the PSModulePath
9-
[System.Environment]::SetEnvironmentVariable('PSModulePath', $UnmungedPSModulePath, [System.EnvironmentVariableTarget]::Machine)
9+
#[System.Environment]::SetEnvironmentVariable('PSModulePath', $UnmungedPSModulePath, [System.EnvironmentVariableTarget]::Machine) #commented becose of long execution time
10+
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name 'PSModulePath' -Value $UnmungedPSModulePath
1011
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath', 'machine')
1112
}
1213
}

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

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

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

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

0 commit comments

Comments
 (0)