我能用Windows PowerShell做什么:保存 Windows PowerShell 别名

注:本篇文章,未在联系作者以及得到许可的情况下, 禁止以任何形式进行转载。

By:Anders      Mail:katrina520@163.com     

保存 Windows PowerShell 别名

Export-Alias cmdlet提供了一种方法,以输出你的Windows PowerShell别名到一个文本文件。在这其中最简单的形式是你可以仅仅使用Export-Alias输出到文本文件。例如,这个命令用一个逗号分隔的值列表输出你的别名文件,将文件保存为 C:/Scripts/Test.txt 。

Export - Alias c:/scripts test.txt

由此这个文本文件将看起来类似这样:

# Alias File
# Exported by : kenmyer
# Date
/ Time : Saturday, May  06 2006   4 : 12 : 53  PM
# Machine : TVSFRANK
" ac " , " Add-Content " , "" , " ReadOnly, AllScope "
" clc " , " Clear-Content " , "" , " ReadOnly, AllScope "
" cli " , " clear-item " , "" , " ReadOnly, AllScope "

另外,你也可以输出你的别名做为一个脚本文件,利用一系列的Set-Alias cmdlets (从而文件可以作为一个Windows Powershell 脚本以配置这些别名) 。要做到这一点,要附加 -as 参数,设定值为"script" 。这个命令看起来是这样的:

Export - Alias c:/scripts test.ps1 – as   " script "

由此文件看起来像这样:

# Alias File
# Exported by : kenmyer
# Date
/ Time : Saturday, May  06 2006   4 : 14 : 04  PM
# Machine : TVSFRANK
set - alias  - Name: " ac "   - Value: " Add-Content "   - Description: ""   - Option: " ReadOnly, AllScope "
set - alias  - Name: " clc "   - Value: " Clear-Content "   - Description: ""   - Option: " ReadOnly, AllScope "
set - alias  - Name: " cli "   - Value: " clear-item "   - Description: ""   - Option: " ReadOnly, AllScope "

你也肯能想要输出单个或者建立名别。例如:假设你已经建立了一个别名,每个以字母X开始。输出这些别名做为一个脚本(从而使它容易对自己的电脑为别人来配置这些相同的别名)只要使用 -name 参数于通配符X* 。

Export-Alias c:scripts est.ps1 -name x*  –as "script"

默认Export-Alias将改写具有相同名称的任何文件;如果一个文件的文件名为Text.txt已经存在,那么Export-Alias将改写那个文件。为了防止这种情况发生,只要添加 -noclobber 参数: 

Export-Alias c:/scripts test.txt -noclobber

如果你运行这个命令,并且test.xml已经存在,你将会得到下列错误信息:

Export - Clixml : File C:/ scripts test.txt already exists  and  NoClobber was specified.

 

 

 

英文原文:http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/export-alias.mspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值