www.Gab.ai

Set PS 5.1 to use PS 7 PSModulePath

The transition to PS 7 will be fun, so might as well prepare by using the D:\PowerShell path now with PS 5.1, set in your $profile in PowerShell and ISE
(And remember, PS 7 will require loading the Visual Studio Code shell, not ISE)

#Set default PS path
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PSModulePath" -Value "D:\PowerShell;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;...1"
#Set the PSModulePath
# Check if the "D:\PowerShell\Modules" directory is present at the beginning of the $env:PSModulePath environment variable
if(($env:PSModulePath -notlike ".\\modules*") or ($env:PSModulePath -notlike "d:\powershell\modules*")){
    # If the your D:|powershell or .\\Modules directory is not present in the default path, append it to the $env:PSModulePath environment variable
    $env:PSModulePath = ((@("d:\powershell\modules") + ($env:PSModulePath -split ";")) -join ";")
    # Log a message to indicate that the directory was added to the $env:PSModulePath environment variable
    else {continue}
}
  1. Make sure and add your full path from your $env:PSModulePath ↩︎

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.