$today=Get-Date -Format "dd-MM-yyyy-HHmm";
$exportFilePath="C:\Maximo\HealthCheck\Reports\PROD_Server_Ports_Health"+$today+".csv";
$appSvr01="PRODMAXIMOAP01.orgxx.com";
$appSvr02="PRODMAXIMOAP01.orgxx.com"
$adminServer="PRODMAXIMOADM01.orgxx.com"
$JVMPorts="9080","9081","9082","9083"
$nodeAgentPorts="2810","9902","9203","9204","7273","8879","9630","7063","11005","11006";
$nodeAdminPorts="2810","9902","9203","9204","7273","8880","9630","7063","11007","11008";
$dmgrPorts="7277","9809","9632","8879","9100","9402","9060","9043","9352","7060","9420","11005","11006";
#Declare combined PortList and ServerList in correct sequence.
#Such that, it matches relevant Port to Server as below
#AP01,AP02,AP01,AP02,ADM01,ADM01
#JVM,JVM,nAgnt,nAgnt,nAdmin,Dmgr
$serverList=$appSvr01,$appSvr02,$appSvr01,$appSvr02,$adminServer,$adminServer
$portListAll = $JVMPorts,$JVMPorts,$nodeAgentPorts,$nodeAgentPorts,$nodeAdminPorts,$dmgrPorts;
$portTypeList = "JVM","JVM","NodeAgent","NodeAgent","NodeAdmin","Dmgr";
$Result=
for ($i=0; $i -lt $serverList.Length; $i++){
$server=$serverList[$i];
$portList=$portListAll[$i];$portType=$portTypeList[$i];
foreach ($port in $portList)
{
$resultHashTable=[Ordered]@{
ServerName=$server
RemoteAddress=''
PortType=$portType
PortNumber=$port
Status=''
}
try{
$tncCheck=tnc $server -p $port
$resultHashTable.ServerName=$tncCheck.ComputerName
$resultHashTable.RemoteAddress=$tncCheck.RemoteAddress
$resultHashTable.PortType=$portType
$resultHashTable.PortNumber=$tncCheck.RemotePort
$resultHashTable.Status=$tncCheck.TcpTestSucceeded
}
catch{
$resultHashTable.PingStatus='N/A'
$resultHashTable.Status='N/A'
}
[PSCustomObject]$resultHashTable
}
}
$Result|Export-Csv $exportFilePath