Override default PowerShell PWD alias only within a script

Viewed 80

I'd like to override the default pwd alias to return just the exact Path, and the change should only occur within the script. Typically, the pwd (Path only) it can be achieved with the following command:

(Get-Location).Path

How can I set this as the new default pwd alias?

1 Answers

Create a function to return the value you want:

function Get-PathOnly
{
  return (Get-Location).Path
}

Set the pwd alias to that function:

Set-Alias pwd Get-PathOnly -Scope Script
Related