如何在 PowerShell 核心中创建永久别名文件?

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

我正尝试在 Windows 上从 PowerShell 5.1 过渡到 PowerShell Core 7.0。在 PowerShell 中,我在 C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 处有一个永久别名文件。但是,当我启动核心终端时,不会加载这些别名。知道我该怎么做才能在启动核心时也执行此文件吗?

添加 Mathias R. Jessen 的评论以便此问题有答案。

"Put them in $profile.AllUsersAllHosts for a default PowerShell 7 on Windows that's C:\Program Files\PowerShell\profile.ps1" – 马蒂亚斯·R·杰森

C:\Program Files\PowerShell\Microsoft.PowerShell_profile.ps1中写一个函数,它会被设置为别名。

例如 Microsoft.PowerShell_profile.ps1:

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

现在您可以 运行 它作为 powershell 核心中的命令 open-profile