powershell - 如何从 Powershell 调用 DOSkey 别名?

标签 powershell cmd environment-variables registry doskey

我有我这样设置的 DOSKey 别名 (Aliases in Windows command prompt) 从注册表调用它,我希望能够从 powershell 运行它;有没有办法做到这一点?它真正做的只是在 %PATH% 环境变量中添加一些东西。

最佳答案

如果您不必使用 DOSKey 并且只想为命令设置别名,则可以使用内置的 Set-Alias 命令,如下所示:

Set-Alias -Name np -Value notepad++

这将在当前的 powershell 窗口打开时,将 np 别名为 notepad++。它还允许您使用 np temp.txt 打开文件。 如果您想坚持这一点,可以将其添加到您的个人资料中。您可以通过编辑 Microsoft.PowerShell_profile.ps1 来做到这一点,简写为:

notepad $profile

随意使用 notepad++ 或您的 PATH 中可能拥有的任何其他编辑器。您可以将 Set-Alias 行添加到文件的底部并保存并关闭它。 然后,当您打开另一个 powershell 实例时,它将具有示例 np 别名可用。

关于powershell - 如何从 Powershell 调用 DOSkey 别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51604545/

相关文章:

powershell - 您可以在 PowerShell v2 脚本中设置对象的 DefaultDisplayPropertySet 吗?

batch-file - 批处理文件读取第一行未使用的文本,然后标记为已使用

java - 如何安装sphinx4?

azure - 查询 Azure 存储帐户已用容量 - PowerShell 脚本?

powershell - PowerShell 中的着色数组筛选器

arrays - 将 xml 中的节点从数组转换为列表 Powershell

windows - 如何回显以数字结尾的字符串?

windows - 批量删除文本文件中的重复行

java - 批处理文件 : "Environment Variable Not Defined"

java - 当使用 Java 的 Runtime.getRuntime().exec() 运行时,从源代码构建 Go 测试失败