[转][PowerShell]ps执行重启IIS
Posted 秤心
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转][PowerShell]ps执行重启IIS相关的知识,希望对你有一定的参考价值。
来自: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的主要内容,如果未能解决你的问题,请参考以下文章
无法在 IIS 托管的 .net web api 项目中运行 powershell 脚本