首页 > 代码库 > 远程重启IIS服务
远程重启IIS服务
方法一:
1 $UserName = "administrator"2 $serverpass = "pass"3 $server = "10.4.19.60"4 $Password = ConvertTo-SecureString $serverpass -AsPlainText –Force5 $cred = New-Object System.Management.Automation.PSCredential($UserName,$Password)6 7 Invoke-Command -ComputerName $server -ScriptBlock { iisreset } -Credential $cred
方法二:
IISRESET.exe remotename /restart
#需要本地和远程计算机上都安装有IIS组件,如果不安装IIS,则无法使用 iisreset.exe 命令
方法三:
1 (Get-WmiObject Win32_Service -ComputerName ServerName -Filter "Name=‘iisadmin‘").InvokeMethod("StopService", $null) 2 Start-Sleep -Seconds 53 (Get-WmiObject Win32_Service -ComputerName ServerName -Filter "Name=‘iisadmin‘").InvokeMethod("StartService", $null)
除此应该还需要重启www服务,未测试。
方法四:
for IIS v6
$srv = "Server Name or IP Address"
$app = "Name of App Pool"
$x = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" -ComputerName $srv -Authentication PacketPrivacy | where-object {$_.Name -eq "W3SVC/AppPools/$app"}
$x.Stop()
$x.Start()
for IIS v7
$srv = "Server Name or IP Address"
$app = "Name of App Pool"
$x = Get-WMIObject -Namespace "root\webAdministration" -Class "ApplicationPool" -ComputerName $srv -Authentication PacketPrivacy | Where-Object {$_.Name -eq $app}
$x.Stop()
$x.Start()
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。