Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

script to get application stats running on multiple windows servers

$
0
0

Hi,

 I am beginner in powershell and trying to write a script to get the different stats of an application/s running on  windows WAS server. am trying to gather all the stats into one custom object and planning the tabular output to send via html mail. am finding it hard to frame logic to get this done and below is piece of script. can somebody guide on this ?

# Get the profiles list in the server

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

$ppath = "profilePath"
$profiles = Get-ChildItem "profilePath" | ForEach-Object { $_.Name }

$SystemInfo = @()

$profiles | ForEach-Object {$_}{
$Obj = New-Object -TypeName PSObject

$pathToCheck = $ppath + $_ + "application path" 
$SerFile = "profilePath" + $_ + "service file"
$ContFile = "profilePath" + $_ + "context file"

if(Test-Path $pathToCheck)
{
#Write-Host "Profile ==>" $_
$Obj | Add-Member -MemberType NoteProperty -Name Profile -Value $_

$PIDFile = $ppath + $_ + "PID file path"

if(test-path $PIDFile)
{

$ProcID = get-content $PIDFile

#Write-Host "PID     ==>" $ProcID


$memTmp = Get-WmiObject -class Win32_PerfFormattedData_PerfProc_Process | where{$_.idprocess -eq $ProcID} | Select WorkingSetPrivate
$memUsage = $memTmp | Select -Expand WorkingSetPrivate



#Write-host "Memory  ==>" $memUsage

}
else{
$ProcID = "PID Not Found"

   }

$Obj | Add-Member -MemberType NoteProperty -Name Memory -Value $memUsage

if(test-path $SerFile)
{
$temp = Get-ChildItem -name $SerFile
$SerStr = $temp.Substring(0,4)

$nm = Get-Service -name *$SerStr* | Select Name
$name = $nm | select -expand Name


$sts = Get-Service -name *$SerStr* | Select Status
$status = $sts | select -expand Status


#Write-Host "Service Name ==>" $name
#write-host "Status " ==> $status
}
else{
$SerStr = "Service Not Found"
   }

$Obj | Add-Member -MemberType NoteProperty -Name Service-Name  -Value $name
$Obj | Add-Member -MemberType NoteProperty -Name Service-Status -Value $status

if(test-path $ContFile)
  {

[XML]$rav = get-content $ContFile

       $tmp1 = @($rav.GetElementsByTagName("context-root"))
       $client = $tmp1[0]."#text"

       #write-host "Environment" ==> $client
   }
else{
$client = "ContextRoot Not Found"
   }$Obj | Add-Member -MemberType NoteProperty -Name Environment -Value $client


write-output $Obj | format-table -autosize  Profile , Environment
}
}


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>