随笔分类 -  PowerShell

摘要:1. 计算脚本执行时间 $start = Get-Date Get-HotFix $end = Get-Date Write-Host -ForegroundColor Red ('Total Runtime: ' + ($end - $start).TotalSeconds) END 阅读全文
posted @ 2021-10-16 08:56 LeoShi2020 阅读(424) 评论(0) 推荐(0) 编辑
摘要:1. 比较运算符 符号 说明 实例 -eq 等于 -ne 不等于 -gt 大于 -ge 大于等于 -lt 小于 -le 小于等于 https://blog.51cto.com/020618/1890587 阅读全文
posted @ 2021-08-31 11:19 LeoShi2020 阅读(64) 评论(0) 推荐(0) 编辑
摘要:1. 字符串长度 $.Length PS /root> "1234567".length 7 2. 字符串包含 if( -not ($storage.Name -match "Local*|NFS")) 阅读全文
posted @ 2021-08-31 11:14 LeoShi2020 阅读(48) 评论(0) 推荐(0) 编辑
摘要:1. 条件判断语句 if (<条件>) {<为真执行该语句>} elseif (<条件>) {<为真执行该语句>} else {<为假自行该语句>} 2. 例子 PS /root> $person_li 白雪公主今年10岁了 小猪今年10岁了 灰太狼今年20岁了 哪吒今年5岁了 if ($perso 阅读全文
posted @ 2021-08-19 13:10 LeoShi2020 阅读(1424) 评论(0) 推荐(0) 编辑
摘要:1. 多条件筛选 PS /root> $person_li 白雪公主今年10岁了 小猪今年10岁了 灰太狼今年20岁了 哪吒今年5岁了 # 找到包含5和20的条目 PS /root> $person_li | where {($_ | Select-String 5) -or ($_ | Selec 阅读全文
posted @ 2021-08-19 13:02 LeoShi2020 阅读(444) 评论(0) 推荐(0) 编辑
摘要:1. PowerShell的函数 function <函数名称>(<参数1>,<参数2>...) {<函数体>} 2. 传参 function person_info ($name="小猪",$age="10") { Write-Output $name"今年"$age"岁了" } PS /root 阅读全文
posted @ 2021-08-19 12:33 LeoShi2020 阅读(71) 评论(0) 推荐(0) 编辑
摘要:1. 查看虚拟机列表 PS /root> Get-VM Name PowerState Num CPUs MemoryGB mysql数据库测试 PoweredOn 8 32.000 中间件测试服务器 PoweredOn 8 16.000 test01 PoweredOn 2 4.000 VMwar 阅读全文
posted @ 2021-08-13 12:58 LeoShi2020 阅读(1023) 评论(0) 推荐(0) 编辑
摘要:1. 连接ESXi服务器 Connect-VIServer -Server <IPAddress> -Protocol <https> -User <root> -Password <pass> PS /root> Connect-VIServer -Server 10.1.1.1 Specify 阅读全文
posted @ 2021-08-13 10:53 LeoShi2020 阅读(316) 评论(0) 推荐(0) 编辑
摘要:1. 查看当前素有的版本 PS /root> Find-Module -Repository PSGallery -Name VMware.PowerCLI -AllVersions | ft -AutoSize Version Name Repository Description 12.3.0. 阅读全文
posted @ 2021-08-13 09:01 LeoShi2020 阅读(761) 评论(0) 推荐(0) 编辑
摘要:# 获取服务信息 PS C:\Users\Administrator> Get-Service win* Status Name DisplayName Stopped WinHttpAutoProx... WinHTTP Web Proxy Auto-Discovery Se... Running 阅读全文
posted @ 2020-02-12 18:18 LeoShi2020 阅读(4126) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示