3

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?

2
  • 1
    First appcmd invoked by psexec on remote computer, but second appcmd invoked on local computer. Is that what you want? Commented Dec 23, 2015 at 11:30
  • No - this is the problem. Commented Dec 23, 2015 at 12:32

3 Answers 3

4

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 
Sign up to request clarification or add additional context in comments.

1 Comment

This is a remote server, your answer does not include remoteness of the server.
1

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

Comments

0

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 

3 Comments

The foreach '-parallel' parameter is reserved for future use. - 7.2.1
@pbies, so I must have come from the future ;). In fact those are chunks of perfectly working scripts, executed powershell -file scriptname.ps1. foreach -parallel is part of PowerShell Workflows available since PowerShell 3.0. Look there, for example PowerShell Workflows: The Basics
PowerShell 7.2.1 tells that -parallel is reserved, but I didn't tried it in workflow. PowerShell 5.1 - tells exactly that I need to use -parallel in workflow.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.