How do I create a permanent alias file in PowerShell core?

Viewed 2158

I'm attempting to transition from PowerShell 5.1 to PowerShell Core 7.0 on Windows. In PowerShell, I have a permanent alias file at C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1. However, when I launch the core terminal, these aliases aren't loaded. Any idea what I can do so that this file is also executed when starting core?

2 Answers

Adding Mathias R. Jessen's comment so that this question has an answer.

"Put them in $profile.AllUsersAllHosts for a default PowerShell 7 on Windows that's C:\Program Files\PowerShell\7\profile.ps1" – Mathias R. Jessen

Write a function in C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1 and it'll be set as alias.

For example in Microsoft.PowerShell_profile.ps1:

function open-profile{
    notepad $PSHOME\Microsoft.PowerShell_profile.ps1
}

Now you can run it as a command in powershell core as open-profile

Related