Windows Powershell腳本執行

在cmd下執行powershell進入shell模式:
變量定義:$i = 10
$a = ifconfig | findstr "192"
Windows下的命令均可以執行如:
date  ping   ipconfig  shutdown -r 
ipconfig | select-string -pattern 255
ipconfig | findstr "Address"
一、設置執行策略:
Dos窗口下執行powershell進入shell模式後執行Set-ExecutionPolicy RemoteSigned
 
二、執行腳本: 
powershell devicelist.ps1
 
三、經常使用腳本:
while (1) {
date >>a.log
sleep 2
ping baidu.com >>a.log
}
 
for($i=0; $i -lt 100;$i=$i+1)
{Write-Host $i
echo "ee"
}
 
do {
Write-Host $i
$i++
}
while ($i -le 5)


if(1){echo "AAA"} else{echo "BBB"}

#行註釋符使用井號(#);塊註釋符使用「<#」和 「#>」來引發一段註釋
 
四、執行python腳本:
$i = 1
while (1) {
date >>20171103.log
echo "$i">>20171103.log
$i++
python devicelist.py
sleep 10
}
-le 
-gt -eq
相關文章
相關標籤/搜索