主页 > 知识库 > Windows Powershell 通过函数扩展别名

Windows Powershell 通过函数扩展别名

热门标签:莫拉克电梯系统外呼怎么设置 地图标注的图案 印台区呼叫中心外呼系统 电话机器人公司招聘 万全县地图标注app 六寸地图标注点怎么删除 腾讯地图标注中心怎么标注 如何根据经纬度百度地图标注 新郑电销机器人一个月多少钱

在Powershell中设置别名的确方便快捷,但是在设置别名的过程中并设置参数的相关信息。尽管别名会自动识别参数,但是如何把经常使用的参数默认设定在别名里面呢?例如Test-Connection -Count 2 -ComputerName,让-”-Count 2″ 固化在别名中。

这时简单的别名无法完成上述需求,可以通过函数来完成它,并且一旦把函数拉过来,定义别名会变得更加灵活。

PS C:\PS> function test-conn { Test-Connection -Count 2 -ComputerName $args}
PS C:\PS> Set-Alias tc test-conn
PS C:\PS> tc localhost

Source    Destination   IPV4Address   IPV6Address               Bytes  Time(ms)
------    -----------   -----------   -----------               -----  --------
test-me-01  localhost    127.0.0.1    ::1                   32    0
test-me-01  localhost    127.0.0.1    ::1                   32    0

有了函数牵线,别名可以完成更高级更强大的功能,其中$args为参数的占位符,经测试,发现这个占位符必须以$args命名,否则不能识别,会抛出异常:
Cannot validate argument on parameter ‘ComputerName'. The argument is null or empty. Supply an arg
nt that is not null or empty and then try the command again.

您可能感兴趣的文章:
  • Windows Powershell 执行文件和脚本
  • Windows Powershell 定义变量
  • Windows Powershell 自动化变量
  • Windows Powershell 环境变量
  • Windows Powershell 变量的作用域

标签:南昌 临汾 汕头 湘潭 疫苗接种 襄阳 喀什 天水

巨人网络通讯声明:本文标题《Windows Powershell 通过函数扩展别名》,本文关键词  Windows,Powershell,通过,函数,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《Windows Powershell 通过函数扩展别名》相关的同类信息!
  • 本页收集关于Windows Powershell 通过函数扩展别名的相关信息资讯供网民参考!
  • 推荐文章