Last active
July 23, 2025 00:19
-
-
Save flcdrg/030c4151a019dcf5447c3c3b45764c15 to your computer and use it in GitHub Desktop.
PowerShell Profile
This file contains hidden or 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
| $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") | |
| function Enable-MSBuild { | |
| # Set this to the value returned by 'vswhere -property instanceId' | |
| #$vsInstanceId2019 = "73b5fa7b" | |
| if ($env:ComputerName -eq "DELPHINIUM") { | |
| $vsInstanceId2022 = "bb2defad" | |
| } | |
| elseif ($env:ComputerName -eq "DELPHINE") { | |
| $vsInstanceId2022 = "7aecd3bd" | |
| } | |
| # If PowerShell module exists, prefer that (could be in either of these places apparently) | |
| if (Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") { | |
| Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" | |
| Enter-VsDevShell -InstanceId $vsInstanceId2022 -ErrorAction SilentlyContinue -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64" | |
| } | |
| elseif (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") { | |
| Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" | |
| Enter-VsDevShell -InstanceId $vsInstanceId2019 -ErrorAction SilentlyContinue -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64" | |
| } | |
| elseif (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\vsdevshell\Microsoft.VisualStudio.DevShell.dll") { | |
| Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\vsdevshell\Microsoft.VisualStudio.DevShell.dll" | |
| Enter-VsDevShell -InstanceId $vsInstanceId2019 -ErrorAction SilentlyContinue -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64" | |
| } | |
| else { | |
| $places = @{ | |
| "$($env:VS140COMNTOOLS)VSVars32.bat" = "2015" | |
| "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" = "2017" | |
| "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" = "2019" | |
| } | |
| $places.GetEnumerator() | Sort-Object -Descending -Property Value | Where-Object { Test-Path $_.Key } | Select-Object -First 1 | ForEach-Object { | |
| cmd /c "`"$($_.Key)`" & set" | | |
| ForEach-Object { | |
| if ($_ -match "=") { | |
| $v = $_.split("=") | |
| set-item -force -path "ENV:\$($v[0])" -value "$($v[1])" | |
| } | |
| } | |
| Write-Host "`nVisual Studio $($_.Value) Command Prompt variables set." -ForegroundColor Yellow | |
| $prefix = "" | |
| if ($isAdmin) { | |
| $prefix = "Administrator: " | |
| } | |
| [System.Console]::Title = "$($prefix)Visual Studio $($_.Value) Windows Powershell" | |
| } | |
| } | |
| } | |
| # Remember directory (not in VS Code) | |
| if (-not (Test-Path env:TERM_PROGRAM)) { | |
| Register-EngineEvent PowerShell.Exiting -Action { | |
| Write-Warning "Saving current location" | |
| [System.Environment]::SetEnvironmentVariable("LocationMemory", (Get-Location).Path, [System.EnvironmentVariableTarget]::User) | |
| } | Out-Null | |
| $lastPath = [System.Environment]::GetEnvironmentVariable("LocationMemory", [System.EnvironmentVariableTarget]::User) | |
| if (($lastPath -ne $null) -and (Test-Path $lastPath)) { | |
| Write-Warning "Restoring location to $lastPath" | |
| Set-Location $lastPath | |
| } | |
| } | |
| # PoshGit | |
| if (Get-Module -ListAvailable -name posh-git) { | |
| Import-Module posh-git | |
| # Need this so posh-git tab expansion still works (even though we're not using the status) | |
| $env:POSH_GIT_ENABLED = $true | |
| } | |
| # Posh Docker | |
| if (Get-Module -ListAvailable -name posh-docker) { | |
| Import-Module posh-docker | |
| } | |
| # Posh NPM | |
| if (Get-Module -ListAvailable -name posh-npm) { | |
| Import-Module posh-npm | |
| } | |
| # Chocolatey profile | |
| $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | |
| if (Test-Path($ChocolateyProfile)) { | |
| Import-Module "$ChocolateyProfile" | |
| } | |
| $configFile = [environment]::GetFolderPath("MyDocuments") + "\ohmyposh.json" | |
| oh-my-posh init pwsh --config $configFile | Invoke-Expression | |
| if (Get-Module -ListAvailable -name Terminal-Icons) { | |
| Import-Module -Name Terminal-Icons | |
| } | |
| Set-PSReadLineOption -HistorySearchCursorMovesToEnd | |
| Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
| Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | |
| function Get-OutdatedModules { | |
| # https://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=832 | |
| Get-InstalledModule | ForEach-Object { $b = (find-module $_.name).version ; if ($b -ne $_.version) { Write-host "$($_.name) has an update from $($_.version) to $b" } } | |
| } | |
| <# | |
| .SYNOPSIS | |
| Delete all merged branches except develop, master, and main | |
| .LINK | |
| https://stackoverflow.com/questions/51171479/how-to-delete-all-merged-local-branches-in-git-with-powershell | |
| #> | |
| function Remove-MergedBranches { | |
| git for-each-ref --format '%(refname:short)' refs/heads --merged | ForEach-Object { If ("develop", "master", "main" -notcontains $_) { git branch $_ -d } } | |
| } | |
| # fnm (Node version manager) | |
| fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression | |
| Write-Output "Use `Enable-MSBuild` to enable MSBuild environment variables." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment