在 Windows 11 上的 PowerShell (oh-my-posh) 中设置别名的问题

问题描述 投票:0回答:1

我在 Windows 11 上尝试使用 PowerShell (oh-my-posh) 设置 alias 时遇到问题。我之前已成功创建别名,例如使用 打开 Notepad++

Set-Alias np path_to_notepad_exe.

但是,我在创建新别名来运行

netsh wlan show profile 
时遇到问题

Set-Alias wsp 'netsh wlan show profile'

.

更新位于

的 user_profile.ps1 文件后
C:\Users\CurrentUserAccount.config\powershell\user_profile.ps1

, 我在运行命令wsp时遇到以下错误:

wsp
The term 'netsh wlan show profile' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

另外,我尝试了多种方法来解决这个问题:

  1. 我更新了我的
    $PROFILE
    并向其中添加了这行代码:
New-Alias -Name wlan -Value "netsh wlan show profile"

  1. 我还尝试使用这样的函数定义:
function Show-WlanProfiles {
    netsh wlan show profile
}

我已确保路径正确并尝试了别名定义的不同变体,但我似乎无法使其工作。我在这里缺少什么?如何正确设置此命令的别名?

任何帮助将不胜感激。谢谢你! alias in user_profile.pa1 the error

powershell alias powershell-cmdlet windows-11 oh-my-posh
1个回答
0
投票

尝试以下代码:

Function Show-WlanProfiles {netsh wlan show profile}
Set-Alias -Name wlan -Value Show-WlanProfiles

阅读更多内容官方文档

© www.soinside.com 2019 - 2024. All rights reserved.