Created
June 27, 2024 15:20
-
-
Save wdormann/f11dcb7d730b9da90cb22cfe20f4871e to your computer and use it in GitHub Desktop.
Override PowerShell's "dir" alias with the CMD.EXE version
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
# Ensure the profile path exists | |
if (!(Test-Path -Path $PROFILE)) { | |
New-Item -Type File -Path $PROFILE -Force | |
} | |
# Define the content to add to the profile | |
$profileContent = @' | |
function Invoke-CMDDir { | |
$cmdArgs = @('/c', 'dir') + $args | |
& cmd.exe $cmdArgs | |
} | |
Remove-Item -Path Alias:dir -Force | |
Set-Alias -Name dir -Value Invoke-CMDDir | |
'@ | |
# Add the content to the profile | |
Add-Content -Path $PROFILE -Value $profileContent | |
# Reload the profile to apply changes | |
. $PROFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment