Skip to content

Commit 76de340

Browse files
SteveL-MSFTTravisEz13
authored andcommitted
corrected use of PSModulePath casing to be consistent with Windows PowerShell (PowerShell#3255)
* corrected use of PSModulePath casing to be consistent with Windows PowerShell addresses PowerShell#3227 * addressing review feedback make "PSModulePath" into const fixed some test workarounds due to failures for external reasons that wasn't meant to be checked in * addressing review feedback make "PSModulePath" into const fixed some test workarounds due to failures for external reasons that wasn't meant to be checked in
1 parent e5da351 commit 76de340

18 files changed

Lines changed: 81 additions & 76 deletions

File tree

assets/powershell.1.ronn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ PowerShell accepts both `-` and `--` prefixed arguments.
9090

9191
These are environment variables used by PowerShell.
9292

93-
* `$PSMODULEPATH`:
93+
* `$PSModulePath`:
9494
A colon (`:`) separated load path for PowerShell modules.
9595

9696
## AUTOMATIC VARIABLES

build.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ function Start-PSPester {
771771
}
772772
else {
773773
try {
774-
$originalModulePath = $env:PSMODULEPATH
774+
$originalModulePath = $env:PSModulePath
775775
if ($Unelevate)
776776
{
777777
Start-UnelevatedProcess -process $powershell -arguments @('-noprofile', '-c', $Command)
@@ -801,7 +801,7 @@ function Start-PSPester {
801801
& $powershell -noprofile -c $Command
802802
}
803803
} finally {
804-
$env:PSMODULEPATH = $originalModulePath
804+
$env:PSModulePath = $originalModulePath
805805
if ($Unelevate)
806806
{
807807
Remove-Item $outputBufferFilePath
@@ -1784,7 +1784,7 @@ function Start-DevPowerShell {
17841784
if (-not $Command) {
17851785
$ArgumentList = @('-NoExit') + $ArgumentList
17861786
}
1787-
$Command = '$env:PSMODULEPATH = Join-Path $env:DEVPATH Modules; ' + $Command
1787+
$Command = '$env:PSModulePath = Join-Path $env:DEVPATH Modules; ' + $Command
17881788
}
17891789

17901790
if ($Command) {

demos/Azure/Azure-Demo.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
###
1111
### Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination <Folder you want this to be installed>
1212
###
13-
### Ensure $env:PSMODULEPATH is updated with the location you used to install.
13+
### Ensure $env:PSModulePath is updated with the location you used to install.
1414
Import-Module AzureRM.NetCore.Preview
1515

1616
### Supply your Azure Credentials

docs/cmdlet-example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ This build/restore process should work anywhere .NET Core works, including Windo
110110
Deployment
111111
----------
112112

113-
In PowerShell, check `$env:PSMODULEPATH` and install the new cmdlet in its own
113+
In PowerShell, check `$env:PSModulePath` and install the new cmdlet in its own
114114
module folder, such as, on Linux,
115115
`~/.powershell/Modules/SendGreeting/SendGreeting.dll`.
116116

src/Microsoft.PowerShell.Activities/Activities/WorkflowJobConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3933,7 +3933,7 @@ private static string AddUsingPrefixToWorkflowVariablesForFunctionCall(CommandAs
39333933
}
39343934
else
39353935
{
3936-
continue; // Something like $env:psmodulepath
3936+
continue; // Something like $env:PSModulePath
39373937
}
39383938
}
39393939
else

src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
namespace System.Management.Automation
1616
{
17+
internal static class Constants
18+
{
19+
public const string PSModulePathEnvVar = "PSModulePath";
20+
}
21+
1722
/// <summary>
1823
/// Encapsulates the basic module operations for a PowerShell engine instance...
1924
/// </summary>
@@ -710,7 +715,7 @@ private static string AddToPath(string basePath, string pathToAdd, int insertPos
710715

711716
/// <summary>
712717
/// Check if the current powershell is likely running in following scenarios:
713-
/// - sxs ps started on windows [machine-wide env:psmodulepath will influence]
718+
/// - sxs ps started on windows [machine-wide env:PSModulePath will influence]
714719
/// - sxs ps started from full ps
715720
/// - sxs ps started from inbox nano/iot ps
716721
/// - full ps started from sxs ps
@@ -734,8 +739,8 @@ private static bool NeedToClearProcessModulePath(string currentProcessModulePath
734739
// so if the current process module path contains any of them, it's likely that the sxs
735740
// ps was started directly on windows, or from full ps. The same goes for the legacy personal
736741
// and shared module paths.
737-
string hklmModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Machine);
738-
string hkcuModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.User);
742+
string hklmModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Machine);
743+
string hkcuModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.User);
739744
string legacyPersonalModulePath = personalModulePath.Replace(winSxSModuleDirectory, winLegacyModuleDirectory);
740745
string legacyProgramFilesModulePath = sharedModulePath.Replace(winSxSModuleDirectory, winLegacyModuleDirectory);
741746

@@ -824,7 +829,7 @@ public static string GetModulePath(string currentProcessModulePath, string hklmM
824829
NeedToClearProcessModulePath(currentProcessModulePath, personalModulePath, sharedModulePath, runningSxS))
825830
{
826831
// Clear the current process module path in the following cases
827-
// - start sxs ps on windows [machine-wide env:psmodulepath will influence]
832+
// - start sxs ps on windows [machine-wide env:PSModulePath will influence]
828833
// - start sxs ps from full ps
829834
// - start sxs ps from inbox nano/iot ps
830835
// - start full ps from sxs ps
@@ -971,7 +976,7 @@ public static string GetModulePath(string currentProcessModulePath, string hklmM
971976
/// </summary>
972977
internal static string GetModulePath()
973978
{
974-
string currentModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Process);
979+
string currentModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Process);
975980
return currentModulePath;
976981
}
977982
/// <summary>
@@ -981,7 +986,7 @@ internal static string GetModulePath()
981986
/// </summary>
982987
internal static string SetModulePath()
983988
{
984-
string currentModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Process);
989+
string currentModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Process);
985990
string systemWideModulePath = ConfigPropertyAccessor.Instance.GetModulePath(ConfigPropertyAccessor.PropertyScope.SystemWide);
986991
string personalModulePath = ConfigPropertyAccessor.Instance.GetModulePath(ConfigPropertyAccessor.PropertyScope.CurrentUser);
987992

@@ -990,7 +995,7 @@ internal static string SetModulePath()
990995
if (!string.IsNullOrEmpty(newModulePathString))
991996
{
992997
// Set the environment variable...
993-
Environment.SetEnvironmentVariable("PSMODULEPATH", newModulePathString);
998+
Environment.SetEnvironmentVariable(Constants.PSModulePathEnvVar, newModulePathString);
994999
}
9951000

9961001
return newModulePathString;
@@ -1013,7 +1018,7 @@ internal static string SetModulePath()
10131018
/// <returns>The module path as an array of strings</returns>
10141019
internal static IEnumerable<string> GetModulePath(bool includeSystemModulePath, ExecutionContext context)
10151020
{
1016-
string modulePathString = Environment.GetEnvironmentVariable("PSMODULEPATH") ?? SetModulePath();
1021+
string modulePathString = Environment.GetEnvironmentVariable(Constants.PSModulePathEnvVar) ?? SetModulePath();
10171022

10181023
HashSet<string> processedPathSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
10191024

src/System.Management.Automation/engine/PropertyAccessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ internal override string GetModulePath(PropertyScope scope)
169169

170170
string fileName = Path.Combine(scopeDirectory, configFileName);
171171

172-
string modulePath = ReadValueFromFile<string>(fileName, "PsModulePath");
172+
string modulePath = ReadValueFromFile<string>(fileName, Constants.PSModulePathEnvVar);
173173
if (!string.IsNullOrEmpty(modulePath))
174174
{
175175
modulePath = Environment.ExpandEnvironmentVariables(modulePath);
@@ -518,11 +518,11 @@ internal override string GetModulePath(PropertyScope scope)
518518
{
519519
if (PropertyScope.CurrentUser == scope)
520520
{
521-
return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.User);
521+
return ModuleIntrinsics.GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.User);
522522
}
523523
else
524524
{
525-
return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Machine);
525+
return ModuleIntrinsics.GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Machine);
526526
}
527527
}
528528

test/powershell/Host/Base-Directory.Tests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ Describe "Configuration file locations" -tags "CI","Slow" {
3030
}
3131

3232
BeforeEach {
33-
$original_PSMODULEPATH = $env:PSMODULEPATH
33+
$original_PSModulePath = $env:PSModulePath
3434
}
3535

3636
AfterEach {
37-
$env:PSMODULEPATH = $original_PSMODULEPATH
37+
$env:PSModulePath = $original_PSModulePath
3838
}
3939

4040
It @ItArgs "Profile location should be correct" {
4141
& $powershell -noprofile `$PROFILE | Should Be $expectedProfile
4242
}
4343

44-
It @ItArgs "PSMODULEPATH should contain the correct path" {
45-
$env:PSMODULEPATH = ""
46-
$actual = & $powershell -noprofile `$env:PSMODULEPATH
44+
It @ItArgs "PSModulePath should contain the correct path" {
45+
$env:PSModulePath = ""
46+
$actual = & $powershell -noprofile `$env:PSModulePath
4747
$actual | Should Match ([regex]::Escape($expectedModule))
4848
}
4949

@@ -72,14 +72,14 @@ Describe "Configuration file locations" -tags "CI","Slow" {
7272
}
7373

7474
BeforeEach {
75-
$original_PSMODULEPATH = $env:PSMODULEPATH
75+
$original_PSModulePath = $env:PSModulePath
7676
$original_XDG_CONFIG_HOME = $env:XDG_CONFIG_HOME
7777
$original_XDG_CACHE_HOME = $env:XDG_CACHE_HOME
7878
$original_XDG_DATA_HOME = $env:XDG_DATA_HOME
7979
}
8080

8181
AfterEach {
82-
$env:PSMODULEPATH = $original_PSMODULEPATH
82+
$env:PSModulePath = $original_PSModulePath
8383
$env:XDG_CONFIG_HOME = $original_XDG_CONFIG_HOME
8484
$env:XDG_CACHE_HOME = $original_XDG_CACHE_HOME
8585
$env:XDG_DATA_HOME = $original_XDG_DATA_HOME
@@ -91,11 +91,11 @@ Describe "Configuration file locations" -tags "CI","Slow" {
9191
& $powershell -noprofile `$PROFILE | Should Be $expected
9292
}
9393

94-
It @ItArgs "PSMODULEPATH should respect XDG_DATA_HOME" {
95-
$env:PSMODULEPATH = ""
94+
It @ItArgs "PSModulePath should respect XDG_DATA_HOME" {
95+
$env:PSModulePath = ""
9696
$env:XDG_DATA_HOME = $TestDrive
9797
$expected = [IO.Path]::Combine($TestDrive, "powershell", "Modules")
98-
$actual = & $powershell -noprofile `$env:PSMODULEPATH
98+
$actual = & $powershell -noprofile `$env:PSModulePath
9999
$actual | Should Match $expected
100100
}
101101

test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ Describe 'use of a module from two runspaces' -Tags "CI" {
2424
}
2525
New-ModuleManifest @manifestParams
2626

27-
if ($env:PSMODULEPATH -notlike "*$TestModulePath*") {
28-
$env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$TestModulePath"
27+
if ($env:PSModulePath -notlike "*$TestModulePath*") {
28+
$env:PSModulePath += "$([System.IO.Path]::PathSeparator)$TestModulePath"
2929
}
3030
}
3131

32-
$originalPSMODULEPATH = $env:PSMODULEPATH
32+
$originalPSModulePath = $env:PSModulePath
3333
try {
3434

3535
New-TestModule -Name 'Random' -Content @'
@@ -67,7 +67,7 @@ Import-Module Random
6767
}
6868

6969
} finally {
70-
$env:PSMODULEPATH = $originalPSMODULEPATH
70+
$env:PSModulePath = $originalPSModulePath
7171
}
7272

7373
}
@@ -76,9 +76,9 @@ Describe 'Module reloading with Class definition' -Tags "CI" {
7676

7777
BeforeAll {
7878
Set-Content -Path TestDrive:\TestModule.psm1 -Value @'
79-
$passedArgs = $args
80-
class Root { $passedIn = $passedArgs }
81-
function Get-PassedArgsRoot { [Root]::new().passedIn }
79+
$passedArgs = $args
80+
class Root { $passedIn = $passedArgs }
81+
function Get-PassedArgsRoot { [Root]::new().passedIn }
8282
function Get-PassedArgsNoRoot { $passedArgs }
8383
'@
8484
$Arg_Hello = 'Hello'

test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ Describe 'NestedModules' -Tags "CI" {
3030
New-ModuleManifest @manifestParams
3131

3232
$resolvedTestDrivePath = Split-Path ((get-childitem TestDrive:\)[0].FullName)
33-
if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) {
34-
$env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
33+
if (-not ($env:PSModulePath -like "*$resolvedTestDrivePath*")) {
34+
$env:PSModulePath += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
3535
}
3636
}
3737

38-
$originalPSMODULEPATH = $env:PSMODULEPATH
38+
$originalPSModulePath = $env:PSModulePath
3939

4040
try {
4141

@@ -120,7 +120,7 @@ using module WithRoot
120120
}
121121

122122
} finally {
123-
$env:PSMODULEPATH = $originalPSMODULEPATH
123+
$env:PSModulePath = $originalPSModulePath
124124
Get-Module @('ABC', 'NoRoot', 'WithRoot') | Remove-Module
125125
}
126126
}

0 commit comments

Comments
 (0)