Good Morning,
My array contains the following
Server Status
Server1 running
Server2 running
Server3 error
Server4 running
The array is named $array and the server column inside the array is dynamic, so the number of server entries will increase and decrease.
I also have a function called $buildhtml that I pass the array to as follows:
Function Buildhtml([array]$Servernames){
Foreach($srv in $servernames){
Write-Output “<PRTG>”
“<result>”
“<channel>Server Name</channel>”
“<value>$status</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“</PRTG>”
}
}
For each server in the array I need to populate the following html with the $server and $status and importantly write-output:
Write-Output “<PRTG>”
“<result>”
“<channel>Server Name</channel>”
“<value>$server</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“<result>”
“<channel>Server Status</channel>”
“<value>$status</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“</PRTG>”
}
So basically I need to end up with something like this. And remember the amount of servers will vary depending on how many are in the array
Write-Output “<PRTG>”
“<result>”
“<channel>Server Name</channel>”
“<value>$server</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“<result>”
“<channel>Server Status</channel>”
“<value>$status</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“</PRTG>”
“<result>”
“<channel>Server Name</channel>”
“<value>$server1</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“<result>”
“<channel>Server Status</channel>”
“<value>$status1</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“<result>”
“<channel>Server Name</channel>”
“<value>$server2</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“<result>”
“<channel>Server Status</channel>”
“<value>$status2</value>”
“<showChart>1</showChart>”
“<showTable>1</showTable>”
“<error>1</error>”
“</result>”
“</PRTG>”
etc…
The problem I have with my function is that the write-output inside the foreach loop only contains 1 server at a time and I need it to contain all the servers from the array that is passed to it. This is because the application that consumes the output doesnt really work if not all the servers are in the write-output html tags