Script to remotely recycle IIS application pools for Exchange 2013 server

I need to be able to remotely recycle the the microsoft exhange application pools for active sync and autodiscocery in IIS on all Exchange 2013 servers. Not sure if this is possible. Does this look right below, please advice where I need corrections:

Add-PSSnapin *exchange*
$cas = (Get-ClientAccessServer).Name

foreach ($server in $cas)
{

Invoke-Command -ComputerName $server -ScriptBlock {
Import-Module WebAdministration
$AutodiscoverAppPool = Get-Item iis:\apppools\MSExchangeAutodiscoverAppPool
$AutodiscoverAppPool.Recycle()
$SyncAppPool = Get-Item iis:\apppools\MSExchangeSyncAppPool;
$SyncAppPool.Recycle()}

July 22nd, 2015 7:33pm

This would be cleaner:

Add-PSSnapin exchange
$sb={
    Import-Module WebAdministration
    $AutodiscoverAppPool = Get-Item iis:\apppools\MSExchangeAutodiscoverAppPool
    $AutodiscoverAppPool.Recycle()
    $SyncAppPool = Get-Item iis:\apppools\MSExchangeSyncAppPool;
    $SyncAppPool.Recycle()
}
Get-ClientAccessServer |
    ForEach-Object{
        Invoke-Command -ComputerName $_.Name -ScriptBlock $sb
    }
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 9:58pm

I actually got an extra error running the script you provided: "Add-PSSnapin : The Windows PowerShell snap-in 'exchange' is not installed on this computer."

But both scripts did give me this error and it also did not include all the CAS servers:

[yyCAyyES02] Connecting to remote server yyCAyyES02 failed with the following error message : The client cannot
connect to the destination specified in the request. Verify that the service on the destination is running and is
accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most
commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more information, see the
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (yyCAyyES02:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
[mmVAmmES01] Connecting to remote server mmVAmmES01 failed with the following error message : The client cannot
connect to the destination specified in the request. Verify that the service on the destination is running and is
accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most
commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more information, see the
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (mmVAmmES01:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
[mmVAmmES02] Connecting to remote server mmVAmmES02 failed with the following error message : The client cannot
connect to the destination specified in the request. Verify that the service on the destination is running and is
accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most
commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more information, see the
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (mmVAmmES02:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
[ttLODttES02] Connecting to remote server ttLOttES02 failed with the following error message : The client cannot
connect to the destination specified in the request. Verify that the service on the destination is running and is
accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most
commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more information, see the
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (ttLOttES02:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
[GttLOttES03] Connecting to remote server ttLOttES03 failed with the following error message : Access is denied. For
more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (ttLOttES03:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken
    + CategoryInfo          : OpenError: (mmVAmmES01:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
[mmVAmmES02] Connecting to remote server mmVAmmES02 failed with the following error message : The client cannot
connect to the destination specified in the request. Verify that the service on the destination is running and is
accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most
commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more information, see the
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (mmVAmmES02:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
[ttLOttES02] Connecting to remote server ttLOttES02 failed with the following error message : The client cannot
connect to the destination specified in the request. Verify that the service on the destination is running and is
accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most
commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more information, see the
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (ttLOttES02:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
July 23rd, 2015 1:17am

Well you didn't say that you didn't have the exchange commands installed. That is up to you to fix or you can remote into an exchange server and retrieve the CAS list.

Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 1:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics