This repository was archived by the owner on Jun 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +41
-10
lines changed Expand file tree Collapse file tree 4 files changed +41
-10
lines changed Original file line number Diff line number Diff line change @@ -194,14 +194,14 @@ Describe "Test the Windows PowerShell Compatibility Session functions" {
194194 }
195195 }
196196
197- It " Should mirror directory changes in the compatibility session" {
197+ It ' Should mirror directory changes in the compatibility session' {
198198 # Verify that the initial directories are sync'ed
199- Invoke-WinCommand { $pwd.Path } | Should - BeExactly $pwd.Path
199+ Invoke-WinCommand { $pwd.Path } | Should - Be $pwd.Path
200200 # Change location and verify that the compat session directory also changed
201201 Push-Location ..
202- Invoke-WinCommand { $pwd.Path } | Should - BeExactly $pwd.Path
202+ Invoke-WinCommand { $pwd.Path } | Should - Be $pwd.Path
203203 # Change back and verify again
204204 Pop-Location
205- Invoke-WinCommand { $pwd.Path } | Should - BeExactly $pwd.Path
205+ Invoke-WinCommand { $pwd.Path } | Should - Be $pwd.Path
206206 }
207207}
Original file line number Diff line number Diff line change @@ -14,10 +14,23 @@ Describe "Test Add-WindowsPSModulePath cmdlet" {
1414 $env: PSModulePath = $originalPsModulePath
1515 }
1616
17- It " Validate Windows PSModulePath is added on Core" {
18- $env: PSModulePath | Should -Not - BeLike " *\WindowsPowerShell\*"
17+ It ' Validate that the system environment variable PSModulePath components are added to the $ENV:PSModulePath' {
1918 Add-WindowsPSModulePath | Should - BeNullOrEmpty
19+ # a table of the current PSModulePath components
20+ [hashtable ] $currentPathTable = @ {}
21+ $env: PSModulePath.split (' ;' ).foreach {$currentPathTable [$_ ] = $true }
2022 $WindowsPSModulePath = [System.Environment ]::GetEnvironmentVariable(" psmodulepath" , [System.EnvironmentVariableTarget ]::Machine)
21- $env: PSModulePath | Should - BeLike " *$WindowsPSModulePath *"
23+ $allComponentsInPath = $true
24+ # Verify that all of the path components in the machine-scoped PSModulePath are
25+ # also in the session module path.
26+ foreach ($pc in $WindowsPSModulePath.Split (' ;' ))
27+ {
28+ if ( -not $currentPathTable.ContainsKey ($pc ) )
29+ {
30+ $allComponents = $false
31+ }
32+ }
33+ $allComponents | Should - Be $true :w
34+
2235 }
2336}
Original file line number Diff line number Diff line change @@ -33,11 +33,12 @@ FunctionsToExport = @(
3333AliasesToExport = @ (' Add-WinPSModulePath' )
3434PrivateData = @ {
3535 PSData = @ {
36- Tags = @ (' Compatibility' , ' Core' )
36+ Tags = @ (' Windows PowerShell' , ' Compatibility' , ' Core' )
37+ Prerelease = ' RC'
3738 LicenseUri = ' https://opensource.org/licenses/MIT'
3839 ProjectUri = ' https://github.com/PowerShell/WindowsCompatibility'
3940 ReleaseNotes = @'
40- This is the first release of this module with the basic commands:
41+ This is the first release candidate (RC) of this module with the following commands:
4142 Initialize-WinSession
4243 Add-WinFunction
4344 Invoke-WinCommand
Original file line number Diff line number Diff line change @@ -733,6 +733,10 @@ function Copy-WinModule
733733
734734function Add-WindowsPSModulePath
735735{
736+ [CmdletBinding (SupportsShouldProcess )]
737+ [OutputType ([void ])]
738+ param ()
739+
736740 if ($PSVersionTable.PSEdition -eq ' Core' -and -not $IsWindows )
737741 {
738742 throw " This cmdlet is only supported on Windows"
@@ -743,6 +747,8 @@ function Add-WindowsPSModulePath
743747 return
744748 }
745749
750+ [bool ] $verboseFlag = $PSBoundParameters [' Verbose' ]
751+
746752 $paths = @ (
747753 $Env: PSModulePath -split [System.IO.Path ]::PathSeparator
748754 " ${Env: UserProfile} \Documents\WindowsPowerShell\Modules"
@@ -753,14 +759,25 @@ function Add-WindowsPSModulePath
753759 )
754760
755761 $pathTable = [ordered ] @ {}
762+ $doUpdate = $false
756763 foreach ($path in $paths )
757764 {
758765 if ($pathTable [$path ])
759766 {
760767 continue
761768 }
769+
770+ if ($PSCmdlet.ShouldProcess ($path , " Add to PSModulePath" ))
771+ {
772+ Write-Verbose - Verbose:$verboseFlag " Adding '$path ' to the PSModulePath."
773+ $doUpdate = $true
774+ }
775+
762776 $pathTable [$path ] = $true
763777 }
764778
765- $Env: PSModulePath = $pathTable.Keys -join [System.IO.Path ]::PathSeparator
779+ if ($doUpdate )
780+ {
781+ $Env: PSModulePath = $pathTable.Keys -join [System.IO.Path ]::PathSeparator
782+ }
766783}
You can’t perform that action at this time.
0 commit comments