码迷,mamicode.com
首页 > 系统相关 > 详细

[转][PowerShell]ps执行重启IIS

时间:2018-08-19 13:06:02      阅读:775      评论:0      收藏:0      [点我收藏+]

标签:log   reac   each   obj   string   -o   command   object   asp   

来自:https://www.aliyun.com/jiaocheng/871477.html

write-output Restarting IIS servers ................ 
$servers= server1 ,Server2
$username=用户名
$password = ConvertTo-SecureString -String 密码 -AsPlainText -Force
$credential =New-Object System.Management.Automation.PSCredential -argumentlist $username ,$password

foreach($server in $servers){
$message= Restarting IIS server : +$server
write-output $message
$sessions=New-PSSession -ComputerName $server -credential $credential
Invoke-Command –Session $sessions -scriptBlock {restart-Service w3svc} 
$message= IIS server Restarted : +$server
write-output $message
}
write-output IIS servers Restarted ...................

 重启本机的IIS 

Invoke-Command -scriptBlock {restart-Service w3svc}

重启某一服务(并排除 net logon)

restart-service WebMVC
restart-service Web* -exclude net logon

参考:https://www.jb51.net/article/53349.htm

https://www.itstrike.cn/Question/264def6e-57be-40d1-a2d0-c8a2afe6f6eb.html

查看 PowerShell 版本:

$psversiontable

参考:https://www.jb51.net/article/53150.htm

 

[转][PowerShell]ps执行重启IIS

标签:log   reac   each   obj   string   -o   command   object   asp   

原文地址:https://www.cnblogs.com/z5337/p/9500680.html

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