Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

PowerShell Script To Stop/Start Application Pools In IIS 7.5 Servers Remotely

$
0
0

Hello:

Currently, I have the following script which works OK inside the server where I am running for one application pool (in the below case DefaultAppPool):

$LogFileLoc="D:\psscripts\RestartAppPoolLog.txt"
#$SepLine="==============================================="
$a = Get-Date | Out-File -append $LogFileLoc
#"Date: " + $a.ToShortDateString() | Out-File -append $LogFileLoc
#"Time: " + $a.ToShortTimeString() | Out-File -append $LogFileLoc
Import-Module WebAdministration
cd IIS:\
cd .\AppPools
 Get-WebAppPoolState DefaultAppPool | Out-File -append $LogFileLoc
 Stop-WebAppPool "DefaultAppPool" | Out-File -append $LogFileLoc
 Start-Sleep -s 10
 Get-WebAppPoolState DefaultAppPool | Out-File -append $LogFileLoc
 Start-WebAppPool "DefaultAppPool"
 Get-WebAppPoolState DefaultAppPool | Out-File -append $LogFileLoc

Now, need help with the following requirements (NOTE: We have 5+ IIS servers for now and have over 10 application pools on each of the IIS servers):

1. First script should read a text file which contains only server names (call it as $ServerList from say d:\psscripts\) and read a text file which contains only the application pool names (call it as $poolist from say d:\pscripts\poolist.txt) . We have identical application pool names across many web servers) and then, execute stop and start of the concerned application pool before going to the next server. The script should go through ALL the servers from the $ServerList besides executing stop/start of the ALL concerned application pool.

2. The stop/start events should be captured to a log file that shows the servername and the application pool name with a message End of file at the end of completion of the script which should also include date/time stamp at the start of the script run and at the end of the script run with a line separation. The log file can be continuous or keep appending to the existing log file. (NOTE: It would be nice if separate log file is created during each run with date/time for uniqueness. But, this is not a must requirement:-))

3. Can use Foreach or while or other methods for looping inside the script.

4. Though not a must requirement, it would be nice to capture errors when executing and write it to the said log file:-)

5. The next requirement is to create another script which runs the stop/start against a specific servername or ip address while accepting user input as follows:

Enter server name or ip address:

Enter application pool name:

There is no need for log file or error capture for this script.

Will greatly appreciate an early response. 

Thanks in advance!

Victor 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles