复制代码
- get-alias
PS D:\> get-alias CommandType Name Definition ----------- ---- ---------- Alias % ForEach-Object Alias ? Where-Object Alias ac Add-Content Alias asnp Add-PSSnapIn Alias cat Get-Content ... |
PS D:\BatHome> ls Directory: D:\BatHome Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 8/30/2013 3:03 PM 0 bathome.txt -a--- 8/30/2013 3:03 PM 0 bbs.txt -a--- 8/30/2013 3:04 PM 0 net.txt PS D:\BatHome> dir Directory: D:\BatHome Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 8/30/2013 3:03 PM 0 bathome.txt -a--- 8/30/2013 3:03 PM 0 bbs.txt -a--- 8/30/2013 3:04 PM 0 net.txt PS D:\BatHome> gci Directory: D:\BatHome Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 8/30/2013 3:03 PM 0 bathome.txt -a--- 8/30/2013 3:03 PM 0 bbs.txt -a--- 8/30/2013 3:04 PM 0 net.txt PS D:\BatHome> get-childitem Directory: D:\BatHome Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 8/30/2013 3:03 PM 0 bathome.txt -a--- 8/30/2013 3:03 PM 0 bbs.txt -a--- 8/30/2013 3:04 PM 0 net.txt |
设置alias的命令复制代码
- 用户自定义的PowerShell的Alias
相当简单的语法,没有什么可多说的。复制代码
- Set-Alias gs Get-Service
复制代码
- Export-Alias -Path a.txt
PS D:\BatHome> Export-Alias -Path a.txt PS D:\BatHome> ls Directory: D:\BatHome Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 8/30/2013 3:08 PM 12032 a.txt -a--- 8/30/2013 3:03 PM 0 bathome.txt -a--- 8/30/2013 3:03 PM 0 bbs.txt -a--- 8/30/2013 3:04 PM 0 net.txt |
# Alias File
# Exported by : HAT
# Date/Time : Friday, August 30, 2013 15:08:46
# Machine : BATHOME
"ac","Add-Content","","ReadOnly, AllScope"
"asnp","Add-PSSnapIn","","ReadOnly, AllScope"
"clc","Clear-Content","","ReadOnly, AllScope"
...
额~杯具了!!!复制代码
- Import-Alias -Path a.txt
PS D:\BatHome> Import-Alias -Path a.txt Import-Alias : Alias not allowed because an alias with the name 'ac' already exists. At line:1 char:13 + Import-Alias <<<< -Path a.txt + CategoryInfo : ResourceExists: (ac:String) [Import-Alias], SessionStateException + FullyQualifiedErrorId : AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand Import-Alias : Alias not allowed because an alias with the name 'asnp' already exists. At line:1 char:13 + Import-Alias <<<< -Path a.txt + CategoryInfo : ResourceExists: (asnp:String) [Import-Alias], SessionStateException + FullyQualifiedErrorId : AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand ... |
# Alias File
# Exported by : HAT
# Date/Time : Friday, August 30, 2013 15:08:46
# Machine : BATHOME
"hat","Stop-Process","","None"
PS D:\BatHome> Import-Alias -Path a.txt PS D:\BatHome> hat cmdlet Stop-Process at command pipeline position 1 Supply values for the following parameters: Id[0]: |
复制代码
- $Profile
PS D:\> $Profile D:\users\HAT\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 |
修改策略级别为Unrestricted:复制代码
- Get-ExecutionPolicy
好的,我们现在来对$Profile进行配置。复制代码
- Set-ExecutionPolicy Unrestricted
false ===> 配置文件不存在(继续步骤2)。复制代码
- test-path $Profile
复制代码
- New-Item -Path $Profile -ItemType file -Force
PS D:\> New-Item -Path $Profile -ItemType file -Force Directory: D:\users\HAT\My Documents\WindowsPowerShell Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 8/30/2013 3:20 PM 0 Microsoft.PowerShell_profile.ps1 |
PS D:\> test-path $Profile True |
OK!我们现在拥有了一个空白的配置文件,其实可以称之为一个空白脚本。复制代码
- notepad $Profile
set-alias marui stop-process
PS D:\> marui cmdlet Stop-Process at command pipeline position 1 Supply values for the following parameters: Id[0]: |
欢迎光临 批处理之家 (http://www.bathome.net/) | Powered by Discuz! 7.2 |