Windows PowerShell基本命令总结(二)
来源:互联网 发布:js调用python脚本文件 编辑:程序博客网 时间:2024/05/19 09:03
先来个开场白。问“忘情水是谁给的”,答“啊哈给的”。这是为什么呢,因为歌词“啊哈给我一杯忘情水”。
这个跟主题没关系哦,好的,我们继续聊聊PowerShell。这篇总结了十大参数,if和switch语句,条件和比较操作。
十大参数:
1) -ErrorAction SilentlyContinue //出现错误不提示
2) -MemberType (Get-Member) //get-member -MemberType 获取对象类型
3) -recurse with Get-ChildItem (Sub-directories) //子目录也显示
4) -force with Get-ChildItem (Lists hidden files) //隐藏文件也显示 Get-ChildItem -recurse -force
5) -auto (Adjust the width with Format-Table) // ft -auto
6) -groupBy (Collate similar items) //分组
7) -filter (Get-Wmiobject "Win32_Process")
8) -list with Get-WmiObject (Get-Eventlog -list)
9) -com (new-Object)
10) -whatif (Test before you commit)
知道某个命令,想知道这个命令的参数,那就用这个命令行:
get-help get-eventlog -full //添加-full参数能显示例子
知道某个参数,想知道哪些命令可以用这个参数,那就用这个命令行:
get-command | where {$_.parameters.keys -contains "groupby"}
if命令:
11) if(...) {...}
12) if else
13) if else if else
14) if -not
15) if -and
16) if -or
例1:
$Calendar = Get-Date
If ($Calendar.day -eq '24' -And $Calendar.Month -eq '12') {
"Christmas Day"
}
Else {
"Not Christmas today!"
}
switch命令:
17) switch (...) {...}
Switch (3) { 1{ "Red" } 2{ "Yellow" } 3{ "Green" } }
conditional operators,like 和match的区别详见本文最下方的例子:
18) -like
19) -match
20) -contains
比较参数:
21) -lt //less than
22) -gt //greater than
23) -eq //equal
like 和match的区别:
PS C:/Users/xxx> Get-Service |where {$_.name -match "wm"}
Status Name DisplayName
------ ---- -----------
Running nvspwmi Hyper-V Networking Management Service
Running wmiApSrv WMI Performance Adapter
PS C:/Users/xxx> Get-Service |where {$_.name -like "wm"}
PS C:/Users/xxx> Get-Service |where {$_.name -like "*wm*"}
Status Name DisplayName
------ ---- -----------
Running nvspwmi Hyper-V Networking Management Service
Running wmiApSrv WMI Performance Adapter
PS C:/Users/xxx> Get-Service |where {$_.name -like "*wm"}
PS C:/Users/xxx> Get-Service |where {$_.name -like "wm*"}
Status Name DisplayName
------ ---- -----------
Stopped wmiApSrv WMI Performance Adapter
- Windows PowerShell基本命令总结(二)
- Windows PowerShell基本命令总结(一)
- Windows PowerShell 命令收集
- windows powershell 命令笔记
- Linux基本命令总结二
- Windows PowerShell的常见命令
- 常用的Windows PowerShell 命令
- Windows PowerShell中scp命令
- 基础篇二---基本命令总结
- Windows PowerShell基本语法及常用命令
- Windows PowerShell基本语法及常用命令
- Windows PowerShell 基本语法及常用命令
- Windows PowerShell 2.0 开发之命令别名
- 使用自定义命令扩展 Windows PowerShell
- Windows管理员常用的PowerShell命令
- 关于Windows PowerShell的想法(二)
- MySQL基本命令(WINDOWS)
- DOS基本命令(二)
- CLR via C#读后感2-类型基础
- SQLDescribeCol和SQLGetData
- ORACLE中的rownum
- Spring对JDBC的支持
- 最大子段和(动态规划)
- Windows PowerShell基本命令总结(二)
- 转:sql的优化
- Start With......Connect by prior..
- 关于vc链接时出错处理
- 以后干什么??
- 使用Qt Style Sheet(1)--QSS语法
- js 获得系统当前时间
- DBA必须掌握的linux命令
- 如何学好C语言