前言
为什么要去学习探究微软的PowerShell???我们都知道大多高手来自 .bat | .vbs 脚本,要知道cmd只是适用于普通人,不过Shell工具中不是还有Bash吗?那有没有继承两者优势的东西,既功能强大而且逼格比较高级的玩意儿?答案是:有的,就是PowerShell,真香!实不相瞒我之前是学习了一些php语法基础,PowerShell它的语法与其是有很多相似的地方或者说有些地方是一毛一样(夸张啦~[滑稽]);还有PowerShell它来自C#能调用.Net对象进行操作。
REVISE: msdos VS powershell VS cmd VS windows script host VS powershell core VS console-.netsomabright.comPowerShell内置可扩展的cmdlet命令,cmd常用的命令同样它也能用(cd | dir | copy | move | cls | echo)
不过这里就有点区别,这些只是cmdlet命令的别名;那是怎样知道这些英文简写是某些cmdlet命令的别名呢?
Get-Alias 获取别名
Get-Alias
Get-Command 获取全部cmdlet、Function函数和Alias别名,范围更大
Get-Command
Get-Help 获取cmdlet命令的参数名称
Get-Help
学到这里,或许你会发现gal是get-alias的别名,gcm是get-command的别名;而help是不是get-help的别名呢???还有你是如何知道那些cmdlet的别名的呢……
前面提到gcm查询的范围很大,包含cmdlet命令、Alias别名和Function函数;机智的同学早已发现了不对劲,目前已经出现了cmdlet命令和Alias别名,还有一个Function……好,很好;现在可以回答help是不是get-help的别名,首先我们不难发现gal -> get-alias、gcm -> get-command 都是三个字母而已,前两个取单词首字母,然后就是你猜第三个字母会取啥,对吧。到这里help肯定就不是get-help的别名,那会不会是Function呢
gal
利用Get-Alias查找cmdlet命令的别名
gal
Cmdlet命令的命名规则是 动词-名词,Get-Command可以根据动词来查看相应的cmdlet命令;那么是否能获取全部cmdlet命令的动词呢?(答案是:有的)
get-verb
Get-Command 可以根据(动词/名词)来查询cmdlet命令,参数-Verb 动词,-Noun 名词
gcm -verb get # 查询get动词开头的cmdlet
返回结果 :
CommandType Name Version Source
----------- ---- ------- ------
Alias Get-DiskSNV 2.0.0.0 Storage
Alias Get-PhysicalDiskSNV 2.0.0.0 Storage
Alias Get-ProvisionedAppxPackage 3.0 Dism
Alias Get-StorageEnclosureSNV 2.0.0.0 Storage
Function Get-AppBackgroundTask 1.0.0.0 AppBackgroundTask
Function Get-AppvVirtualProcess 1.0.0.0 AppvClient
Function Get-AppxLastError 2.0.0.0 Appx
Function Get-AppxLog 2.0.0.0 Appx
Function Get-AssignedAccess 1.0.0.0 AssignedAccess
Function Get-AutologgerConfig 1.0.0.0 EventTracingManagement
Function Get-BCClientConfiguration 1.0.0.0 BranchCache
Function Get-BCContentServerConfiguration 1.0.0.0 BranchCache
Function Get-BCDataCache 1.0.0.0 BranchCache
Function Get-BCDataCacheExtension 1.0.0.0 BranchCache
Function Get-BCHashCache 1.0.0.0 BranchCache
Function Get-BCHostedCacheServerConfiguration 1.0.0.0 BranchCache
Function Get-BCNetworkConfiguration 1.0.0.0 BranchCache
Function Get-BCStatus 1.0.0.0 BranchCache
……(这里省略很多)
gcm -noun computer # 根据名词computer查询cmdlet
返回结果 :
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Add-Computer 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Checkpoint-Computer 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Remove-Computer 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Rename-Computer 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Restart-Computer 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Restore-Computer 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Stop-Computer 3.1.0.0 Microsoft.PowerShell.Management
好像遗漏了什么,哦,应用程序
若有同学安装过vim或neovim,并设置环境变量;就可以使用cat命令查看文件内容。没有安装过也没有关系,可以查询cmd或powershell可执行文件存放的位置
gcm