码迷,mamicode.com
首页 > Windows程序 > 详细

Windows Powershell脚本执行

时间:2017-11-04 00:23:49      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:str   rem   let   数字   dash   html   while   rip   color   

在cmd下执行powershell进入shell模式:
技术分享
Windows下的命令都可以执行如:
date  ping   ipconfig  shutdown -r 
ipconfig | select-string -pattern 255
ipconfig | findstr "Address"
1、执行脚本准备:
Get-ExecutionPolicy
你可以选择使用的执行策略有:
Restricted - 脚本不能运行。
RemoteSigned - 本地创建的脚本可以运行,但从网上下载的脚本不能运行(除非它们拥有由受信任的发布者签署的数字签名)。
AllSigned – 仅当脚本由受信任的发布者签名才能运行。
Unrestricted – 脚本执行不受限制,不管来自哪里,也不管它们是否有签名。
你可以使用下面的cmdlet命令设置PowerShell的执行策略:
 Set-ExecutionPolicy <policy name>
 Set-ExecutionPolicy RemoteSigned
 
2、如何执行脚本: 
C:\Scripts\Script.ps1
OR
.\Script.ps1
OR
powershell devicelist.ps1
 
3、常用脚本:
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)
 
4、执行python脚本:
$i = 1
while (1) {
date >>20171103.log
echo "$i">>20171103.log
$i++
python devicelist.py
sleep 10
}
-le 
-gt
-eq

Windows Powershell脚本执行

标签:str   rem   let   数字   dash   html   while   rip   color   

原文地址:http://www.cnblogs.com/v5captain/p/7780466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!