【问题标题】:how to operate On List of IIS Application Pools On Remote Server Using Powershell?如何使用 Powershell 对远程服务器上的 IIS 应用程序池列表进行操作?
【发布时间】:2013-05-06 10:52:00
【问题描述】:

我正在尝试构建 powershell 程序,它将:

  1. 连接到远程服务器
  2. 显示活动服务器上活动 IIS 应用程序池的数量
  3. 根据选择(1,2,3,4,....n 等),它将重置应用程序池

你能给我一些建议吗?

【问题讨论】:

    标签: iis powershell pool


    【解决方案1】:

    试试这个:

    [Reflection.Assembly]::LoadWithPartialName('Microsoft.Web.Administration')
    $sm = [Microsoft.Web.Administration.ServerManager]::OpenRemote('server1')
    $sm.ApplicationPools['AppPoolName'].Recycle()
    

    【讨论】:

      【解决方案2】:

      在已经给出的答案的基础上,尝试以下操作。它使用 powershell 远程处理,特别是 Invoke-Command,因此您需要熟悉它。

      [cmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="High")] 
      param
      (
          [parameter(Mandatory=$true,ValueFromPipeline=$true)] 
          [string]$ComputerName,
      
          [parameter(Mandatory=$false)] 
          [System.Management.Automation.PSCredential]$Credential
      )
      begin
      {
          if (!($Credential))
          {
              # Prompt for credentials if not passed in
              $Credential = get-credential
          }
      
          $scriptBlock = {
      
              Import-Module WebAdministration
      
              # Get all running app pools
              $applicationPools = Get-ChildItem IIS:\AppPools | ? {$_.state -eq "Started"}
              $i = 0
      
              # Display a basic menu
              Write-Host "`nApplication Pools`n"
              $applicationPools | % {
                  "[{0}]`t{1}" -f $i, $($applicationPools[$i].Name)
                  $i++
              }
      
              # Get their choice
              $response = Read-Host -Prompt "`nSelect Application Pool to recycle"
      
              # Grab the associated object, which will be null 
              # if an out of range choice was entered
              $appPool = $applicationPools[$response]
      
              if ($appPool)
              {
                  "Recycling '{0}'" -f $appPool.name
                  $appPool.recycle()
              }
          }
      }
      process
      {
          Invoke-Command -ComputerName $computerName -Credential $credential -ScriptBlock $scriptBlock 
      }
      

      【讨论】:

        【解决方案3】:

        我无法帮助现有代码,但其中一些链接

        1. 查看远程 powershell 会话 here

        2. 查看网络Server (IIS) Administration Cmdlets in Windows PowerShell,特别是Get-WebApplicationGet-WebAppPoolState

        3. 如果重置意味着停止,那么您可以查看Stop-WebAppPool

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-11-03
          • 2016-04-24
          • 1970-01-01
          • 2021-04-22
          • 2020-12-12
          相关资源
          最近更新 更多