OK, I'm piggybacking off my previous question Powershell script to get IIS app pool recycling time from servers and wondering what I'm doing wrong
I have a list of IIS app pools (apppools.txt) and a list of servers (servers.txt)
When I run it as written below, the only output I get is the FIRST app pool from the list for each node. Can anybody help me find my (probably very simple) mistake?
Output example:
"ServerName","AppPool","RecycleTime"
"serverS26","Pool1","04:10:00"
"serverS27","Pool1","04:10:00"
When I would expect to get about 10 app pools and their respective recycling times. I'm sure it's something stupid with my ICM Params or arguments.
$apppools =gc c:\temp\apppools.txt
$servers = Get-Content C:\temp\servers.txt
foreach ($server in $servers){
Invoke-Command -ComputerName $server -argumentlist @($apppools) -scriptblock {
param($apppools)
$servername = hostname
$infoObject = New-Object PSObject
import-module webadministration
foreach ($a in $apppools){
$recycle = (Get-ItemProperty -Path "IIS:\AppPools\$a" -Name recycling.periodicRestart.schedule.collection).value.tostring()}
Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $Servername
Add-Member -inputObject $infoObject -memberType NoteProperty -name "AppPool" -value $a
Add-Member -inputObject $infoObject -memberType NoteProperty -name "RecycleTime" -value $recycle
$infoObject
} | Select-Object * -ExcludeProperty PSComputerName, RunspaceId, PSShowComputerName | Export-Csv -append -path "C:\temp\recycling.csv" -NoTypeInformation
}
(,$apppools)see stackoverflow.com/questions/7152740/…invoke-command -computername $serverswould run faster.(, $apppools)is enough - you ran into an unrelated follow-up problem, which you can simply solve as follows: place the$infoObject = New-Object PSObjectstatement inside yourforeach ($a in $apppools)loop.$infoObjectstatement into theforeachloop; here's a minimal example:foreach ($a in 1..3) { $infoObject = new psobject; $infoObject | Add-Member foo ('bar'+$a) ; $infoObject }