zoukankan      html  css  js  c++  java
  • 远程重启IIS服务

    方法一:

    1 $UserName = "administrator"
    2 $serverpass = "pass"
    3 $server = "10.4.19.60"
    4 $Password = ConvertTo-SecureString $serverpass -AsPlainText –Force
    5 $cred = New-Object System.Management.Automation.PSCredential($UserName,$Password)
    6 
    7 Invoke-Command -ComputerName $server -ScriptBlock { iisreset } -Credential $cred

     该方法在重启Windows Server 2003上的IIS服务时,会出现如下错误信息:

     但是在重启Windows Server 2012 R2上的IIS服务时,可以成功,应该是与PS版本有关

    方法二:

    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 5
    3 (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 "rootMicrosoftIISv2" -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 "rootwebAdministration" -Class "ApplicationPool" -ComputerName $srv -Authentication PacketPrivacy | Where-Object {$_.Name -eq $app}
    $x.Stop()
    $x.Start()

  • 相关阅读:
    【团队分享之二】IT团队绩效提升的一些见解
    我的ef连接mysql之旅
    Python3.5-20190501-廖老师的
    新装ubantu 18.04(自用)
    nginx配置url重写
    docker中crontab无法执行
    bootstrap
    mysql set
    mysqldump导出数据
    XGBoost 学习调参的例子
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/3925675.html
Copyright © 2011-2022 走看看