Last active
August 9, 2019 15:50
-
-
Save BoredComputerguy/e0d8a0e7cd1e849ab416379e80833e97 to your computer and use it in GitHub Desktop.
Powershell profile switch functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ProdPath = "c:\scripts" | |
$DevPath = "C:\Users\<account name>\source\repos\<internal repo>" | |
$ModuleNamePrefix = "<Prefix>*" #all of my modules begin with the same letters so I can find them easily and not disturb other loaded modules | |
$PromptENV = 'Prod' # this is used in my prompt function to indicate which modules are loaded/available | |
function Switch-Dev{ | |
[CmdLetBinding()] | |
param() | |
Write-Verbose "Function: Switch-Dev" | |
if($env:PSModulePath -like "*$ProdPath*"){ | |
$env:PSModulePath = ($env:PSModulePath).replace([regex]::Escape(";$ProdPath"),"") | |
} | |
$env:PSModulePath += ";$DevPath" | |
Remove-Module $ModuleNamePrefix -ErrorAction Continue | |
Get-Module $ModuleNamePrefix -ListAvailable | Import-Module -Force -ErrorAction SilentlyContinue | |
Get-Module $ModuleNamePrefix |Select name,ModuleBase | |
Set-Location $Devpath | |
$script:PromptENV = 'Dev' | |
} | |
function Switch-Clean{ | |
[CmdLetBinding()] | |
param() | |
Write-Verbose "Function: Switch-Clean" | |
$env:PSModulePath = ($env:PSModulePath).replace([regex]::Escape(";$Devpath"),"") | |
$env:PSModulePath = ($env:PSModulePath).replace([regex]::Escape(";$ProdPath"),"") | |
Remove-Module $ModuleNamePrefix | |
Set-Location "C:\Users\$Username\Desktop" | |
$script:PromptENV = 'None' | |
} | |
function Switch-Prod{ | |
[CmdLetBinding()] | |
param() | |
Write-Verbose "Function: Switch-Prod" | |
if($env:PSModulePath -like "*$DevPath*" -and $env:PSModulePath -notlike "*$ProdPath*"){ | |
$env:PSModulePath = ($env:PSModulePath).replace([regex]::Escape(";$Devpath"),"") | |
} | |
$env:PSModulePath += ";$ProdPath" | |
Remove-Module $ModuleNamePrefix -ErrorAction Continue | |
Get-Module $ModuleNamePrefix -ListAvailable | Import-Module -Force -ErrorAction SilentlyContinue | |
Get-Module $ModuleNamePrefix |Select name,ModuleBase | |
Set-Location $ProdPath | |
$script:PromptENV = 'Prod' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment