script to get application stats running on multiple windows servers


hi,

 i beginner in powershell , trying write script different stats of application/s running on  windows server. trying gather stats 1 custom object , planning tabular output send via html mail. finding hard frame logic done , below piece of script. can guide on ?

# profiles list in 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
}
}

hi ravi0211,

the script below may helpful you, can filter process based on property "idprocess" , services based on service "name":

$pids=@() $output=@() $output1=@() get-content d:\processid.txt|foreach{ $pids+=$_} #store processid array get-wmiobject -class win32_perfformatteddata_perfproc_process | foreach{ if ($pids -contains $_.idprocess){#filter processid listed in file d:\processid.txt $obj = new-object -typename psobject $obj | add-member -membertype noteproperty -name idprocess              -value $_.idprocess $obj | add-member -membertype noteproperty -name memory                 -value $_.workingsetprivate $output+=$obj} }  $services = get-content d:\service.txt foreach($service in $services){ get-service | foreach{ if ($_.name –like “*$service*”){#filter service based on service name stored in d:\service.txt $obj1 = new-object -typename psobject $obj1 | add-member -membertype noteproperty -name service-name               -value $_.name $obj1 | add-member -membertype noteproperty -name service-status         -value $_.status $output1+=$obj1} } } $output $output1

hope helps.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2