问题
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