Reputation: 724
I have a PowerShell script:
& $psexec $serveraddr -u $remoteuser -p $remotepass -accepteula C:\Windows\System32\inetsrv\appcmd.exe list apppool /xml | C:\Windows\System32\inetsrv\appcmd.exe recycle apppool /in
that I am using to recycle all IIS pools. The problem is that only default, given from IIS pools are recycled. No private pools are recycled. They are not found by the second appcmd. First appcmd finds all pools, given by IIS and private.
Error is:
ERROR ( message:Nie można odnaleźć obiektu APPPOOL o identyfikatorze "Core1". )
from polish language it is:
ERROR ( message: Can't find object APPPOOL with id "Core1". )
I can't recycle private pools. Is there a way to bypass this?
Upvotes: 3
Views: 9539
Reputation: 1429
This is an overkill for your question, but you might be interested in the general alternate approach to do something in parallel on the several servers:
$servers=@('server1', 'server2', 'server3')
$recycleAppPools = {
echo $(Get-Wmiobject -Class Win32_ComputerSystem).Name
appcmd list apppools /state:Started /xml | appcmd recycle apppools /in
echo "`n"
}
workflow Perform-Deployment {
Param ($servers, $actionBlock)
# Run on all servers in parallel
foreach -parallel ($server in $servers) {
"Doing on $server..."
# Execute script on the server
InlineScript {
$scriptBlock = [scriptblock]::Create($Using:actionBlock)
Invoke-Command -computername $Using:server -ScriptBlock $scriptBlock
}
}
}
cls
# Execute workflow
Perform-Deployment $servers $recycleAppPools
Moreover, you could pass parameters to your script block, like, for example:
$DeployPythonPackage = {
param($venv, $pythonPackagePath)
& "$venv\scripts\pip" install --upgrade $pythonPackagePath
}
workflow Perform-Deployment {
Param ($servers, $actionBlock, $venv, $pythonPackagePath)
# Run on all servers in parallel
foreach -parallel ($server in $servers) {
"Deploying Python package '$pythonPackagePath' on $server..."
# Execute script on the server
InlineScript {
$scriptBlock = [scriptblock]::Create($Using:actionBlock)
Invoke-Command -computername $Using:server -ScriptBlock $scriptBlock `
-ArgumentList $Using:venv, $Using:pythonPackagePath
}
}
}
cls
# Execute workflow
Perform-Deployment $servers $DeployPythonPackage $venv $pythonPackagePath
Upvotes: 0
Reputation: 280
This is a one liner to recyle all Applications Pools :
& $env:windir\system32\inetsrv\appcmd list apppools /state:Started /xml | & $env:windir\system32\inetsrv\appcmd recycle apppools /in
Upvotes: 4
Reputation: 724
So the second part of the command is executed locally. I've changed the script to recycle every each pool by single commands:
& $psexec $server -u $remoteuser -p $remotepass -accepteula C:\Windows\System32\inetsrv\appcmd.exe recycle apppool /apppool.name:Core1
Upvotes: 1