Recycle Application Pool using Powershell Script

╄→尐↘猪︶ㄣ 提交于 2020-01-04 04:32:27

问题


I want to recycle my application pool using one liner command which I can put in my powershell script. I added the following code in my powershell script:

Import-Module WebAdministration

$site = "Default Web Site"

$pool = (Get-Item "IIS:\Sites\$site"| Select-Object applicationPool).applicationPool

Restart-WebAppPool $pool

But I am getting an error that name IIS doesn't exist. Please advise


回答1:


I like when answers are short and simple, like this...

Restart-WebAppPool (Get-Website -Name <YourSiteName>).applicationPool



回答2:


You can use appcmd.exe:

appcmd recycle apppool /apppool.name='MyAppPool'

You can also retrieve the corresponding WMI instance and invoke the Recycle() method:

$myAppPool = Get-WmiObject -Namespace root\WebAdministration -Class ApplicationPool -Filter "Name = 'MyAppPool'"
$myAppPool.Recycle()



回答3:


Import-Module WebAdministration

$site = "MySite"
$pool = (Get-Item "IIS:\Sites\$site"| Select-Object applicationPool).applicationPool

#Recycle the application pool:
Restart-WebAppPool $pool



回答4:


The following command works for me

invoke-command -computername servername -scriptblock {C:\Windows\System32\inetsrv\appcmd.exe recycle apppool "apppoolname"}



回答5:


Maybe someone will find this one useful as well:

Write-Host "App Pool Recycling Started...."
& $env:windir\system32\inetsrv\appcmd list apppools /state:Started /xml | & $env:windir\system32\inetsrv\appcmd recycle apppools /in 
Write-Host "App Pool Recycling Completed"

Works for me in AWS through Run command.



来源:https://stackoverflow.com/questions/38311797/recycle-application-pool-using-powershell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!