我在 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.
另外,我尝试了多种方法来解决这个问题:
$PROFILE
并向其中添加了这行代码:New-Alias -Name wlan -Value "netsh wlan show profile"
function Show-WlanProfiles {
netsh wlan show profile
}
我已确保路径正确并尝试了别名定义的不同变体,但我似乎无法使其工作。我在这里缺少什么?如何正确设置此命令的别名?
尝试以下代码:
Function Show-WlanProfiles {netsh wlan show profile}
Set-Alias -Name wlan -Value Show-WlanProfiles
阅读更多内容官方文档