Windows Powershell Foreach 循环
下面举两个例子:
$array=7..10 foreach ($n in $array) { $n*$n } #49 #64 #81 #100 foreach($file in dir c:windows) { if($file.Length -gt 1mb) { $File.Name } } #explorer.exe #WindowsUpdate.log
这里只为了演示foreach,其实上面的第二个例子可以用Foreach-Object更简洁。
PS C:Powershell> dir C:Windows | where {$_.length -gt 1mb} |foreach-object {$_.Name} explorer.exe WindowsUpdate.log
Windows Powershell Do While 循环
继续与终止循环的条件do-while()会先执行再去判断,能保证循环至少执行一次。PSC:Powershelldo{$n=Read-Host}while($n-ne0)10100992012世界末日为什么不退出因为条件
Powershell小技巧之获取MAC地址
在Powershell中获取MAC地址不是很难。这里就有一种方法:PSgetmac/FOCSV|ConvertFrom-CsvPhysicalAddressTransportName------------------------------5C-51-4F-62-F2-7DDeviceTcpip_{FF034A8
Powershell小技巧之记录脚本的操作
你可能知道在PS控制台(不是ISE编辑器),你可以打开脚本日志PSStart-Transcript你将记录所有输入的命令和所有的结果到这个文件。不幸的是它虽然运行在
标签:小技巧,脚本,的是,例子,条件