Skip to content

Instantly share code, notes, and snippets.

@wdormann
Created June 27, 2024 15:20
Show Gist options
  • Save wdormann/f11dcb7d730b9da90cb22cfe20f4871e to your computer and use it in GitHub Desktop.
Save wdormann/f11dcb7d730b9da90cb22cfe20f4871e to your computer and use it in GitHub Desktop.
Override PowerShell's "dir" alias with the CMD.EXE version
# 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