How To start/stop IIS 6.0/7.0 remotely using PowerShell Scripts?

后端 未结 6 2640
一向
一向 2021-02-20 04:42

I have two servers Server A and Server B. I want to stop server A from Server B remotely using Powershell script.

6条回答
  •  日久生厌
    2021-02-20 04:57

    You can use get-wmiobject cmdlt with different NameSpace for different versions of IIS v6 or v7, below pipelining command can be used for such operations in IIS locally or remotely

    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()
    

    you need to have sufficient account privilege for these operations, event though i prefer to do $x.Recycle() for my websites.

提交回复
热议问题