摘要: 1 [int]$num=0 2 do 3 { 4 $num+=1 5 if($num%2) 6 { 7 "$num"+" 是奇数" 8 }else{ 9 "$num"+" 是偶数" 10 } 11 } 12 until($num -ge 10 或 1 [int]$num=0 2 do 3 { 4 $ 阅读全文
posted @ 2017-06-30 18:15 PowerShell届的小白白 阅读(2181) 评论(0) 推荐(0) 编辑
 
摘要: 1 $num=0 2 do 3 { 4 $num 5 $num+=1 6 } 7 while($num -le 10) 或是用until 或是用until 结果 阅读全文
posted @ 2017-06-30 17:59 PowerShell届的小白白 阅读(1147) 评论(0) 推荐(0) 编辑
 
摘要: 1-10的循环 当然之前前一篇中所写到的1..9你也可以直接在ps中写道 1..10 运行结果也是一样的。 也可以这样 或 这里的$_代表当前循环,仅只能在当前循环内使用(无法在多层for内使用,而且一般在处理大问题中也尽量不要用循环去处理管道命令,这会减慢程序执行速度) ForEach的使用,枚举 阅读全文
posted @ 2017-06-30 17:43 PowerShell届的小白白 阅读(345) 评论(0) 推荐(0) 编辑
 
摘要: 变量的以变量调用方法 变量的类型 通常变量的类型有很多,这里就不一一例举了,变量类型有哪些请自行百度。 如果你需要获取一个变量的类型,想知道他是什么类型可用: 定义变量类型 整数变量类型 1 '定义短整型' 2 [int16]$num1=-[System.Math]::Pow(2,15) 3 [in 阅读全文
posted @ 2017-06-30 17:10 PowerShell届的小白白 阅读(812) 评论(0) 推荐(0) 编辑

2017年9月8日

摘要: 1 New-Item -ItemType File 1.txt -Force #新建文本文件 2 Compress-Archive -Path '1.txt' -DestinationPath '1.zip' -Force #压缩为zip 3 Expand-Archive -Path '1.zip' -DestinationPath '新建文件夹' -Force #解压到新文件夹内 阅读全文
posted @ 2017-09-08 19:51 PowerShell届的小白白 阅读(3012) 评论(0) 推荐(0) 编辑
 
摘要: 1 function DateDiff 2 { 3 param([Parameter(Mandatory=$true)][datetime]$starttime,[datetime]$endtime,[string]$formatdate='D') 4 [long]$firsttime+=[long]((date $starttime).ToOADate()) 5 [long]$las... 阅读全文
posted @ 2017-09-08 19:12 PowerShell届的小白白 阅读(268) 评论(0) 推荐(0) 编辑
 
摘要: 1 [char[]][int[]]$char=65..90 2 $char -join ',' 3 [int[]][char[]]$ascii=$char 4 $ascii -join ',' A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,... 阅读全文
posted @ 2017-09-08 19:07 PowerShell届的小白白 阅读(1530) 评论(0) 推荐(0) 编辑

2017年9月6日

摘要: 1 '{0:d4}' -f 10 2 '数字的补零';{} 3 '{0:f4}' -f 10 4 '保留小数位数';{} 5 '{0:p2}' -f 0.4567 6 '转换为百分比';{} 7 '{0:x}' -f 255 8 '转换为十六进制';{} 9 '{0:X}' -f 255 10 '以大写字母方式转换为十六进制';{} 11 '{0:X8}' -f 255 12 ... 阅读全文
posted @ 2017-09-06 23:53 PowerShell届的小白白 阅读(1479) 评论(0) 推荐(0) 编辑
 
摘要: 1 [System.IO.DriveInfo]::GetDrives()|Where-Object{$_.DriveType -eq 3}|ForEach-Object{$_.Name} C:\ D:\ E:\ F:\ 阅读全文
posted @ 2017-09-06 23:01 PowerShell届的小白白 阅读(359) 评论(0) 推荐(0) 编辑

2017年8月24日

摘要: 1 function Run([string]$name,$var,[bool]$wait_exp){ 2 $startclass = Get-CimClass -ClassName Win32_ProcessStartup 3 $startinfo = New-CimInstance -CimClass $startclass -Property @{ShowWindow... 阅读全文
posted @ 2017-08-24 03:06 PowerShell届的小白白 阅读(436) 评论(0) 推荐(0) 编辑
 
摘要: 1 function Pause(){ 2 [System.Console]::Write('按任意键继续...') 3 [void][System.Console]::ReadKey(1) 4 } 5 [System.Console]::Title='控制台常用方法' 6 0..15|ForEach-Object{ 7 [System.Console]::... 阅读全文
posted @ 2017-08-24 01:58 PowerShell届的小白白 阅读(1220) 评论(0) 推荐(0) 编辑
 
摘要: 1 function Pause(){ 2 [System.Console]::Write('按任意键继续...') 3 [void][System.Console]::ReadKey(1) 4 } 5 pause 阅读全文
posted @ 2017-08-24 01:19 PowerShell届的小白白 阅读(1996) 评论(0) 推荐(0) 编辑
 
摘要: 可以匹配到QQ为名的结果 阅读全文
posted @ 2017-08-24 01:05 PowerShell届的小白白 阅读(3537) 评论(0) 推荐(0) 编辑
 
摘要: 如果你学过其他的高级语言一定对Switch不陌生,下面讲解一下基本语法。 例1: 例2: 当然也可以配合使用正则表达式 当然你觉得麻烦还可以开启正则表达式参数 开启通配符模式 开启精确模式,当前模式下必须条件完美匹配,才能符合条件语句 开启大小写敏感模式,当前模式下,区分大小写(默认是不区分大小写) 阅读全文
posted @ 2017-08-24 00:44 PowerShell届的小白白 阅读(1014) 评论(0) 推荐(0) 编辑