Contact Info

Crumbtrail

ActiveXperts.com » Administration » Scripts » WMI » perl sample

Win32_PerfFormattedData_TermService_TerminalServicesSession perl sample code

The foundations for Manageability in Windows is Windows Management Instrumentation (WMI; formerly WBEM) and WMI extensions for Windows Driver Model (WDM).

ActiveXperts Network Monitor provides the ability to build monitor check routines based on WMI. ActiveXperts has collected more than a hundred WMI samples. You can use these samples as a base for new check routines you can write yourself. The Win32_PerfFormattedData_TermService_TerminalServicesSession WMI class can be used in ActiveXperts Network Monitor to monitor your servers.


Sample Code

use strict;
use Win32::OLE('in');

use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;

my @computers = ("\localhost");
foreach my $computer (@computers) {
   print "\n";
   print "==========================================\n";
   print "Computer: $computer\n";
   print "==========================================\n";

   my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or die "WMI connection failed.\n";
   my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_PerfFormattedData_TermService_TerminalServicesSession", "WQL",
                  wbemFlagReturnImmediately | wbemFlagForwardOnly);

   foreach my $objItem (in $colItems) {
      print "Caption: $objItem->{Caption}\n";
      print "Description: $objItem->{Description}\n";
      print "Frequency_Object: $objItem->{Frequency_Object}\n";
      print "Frequency_PerfTime: $objItem->{Frequency_PerfTime}\n";
      print "Frequency_Sys100NS: $objItem->{Frequency_Sys100NS}\n";
      print "HandleCount: $objItem->{HandleCount}\n";
      print "InputAsyncFrameError: $objItem->{InputAsyncFrameError}\n";
      print "InputAsyncOverflow: $objItem->{InputAsyncOverflow}\n";
      print "InputAsyncOverrun: $objItem->{InputAsyncOverrun}\n";
      print "InputAsyncParityError: $objItem->{InputAsyncParityError}\n";
      print "InputBytes: $objItem->{InputBytes}\n";
      print "InputCompressedBytes: $objItem->{InputCompressedBytes}\n";
      print "InputCompressFlushes: $objItem->{InputCompressFlushes}\n";
      print "InputCompressionRatio: $objItem->{InputCompressionRatio}\n";
      print "InputErrors: $objItem->{InputErrors}\n";
      print "InputFrames: $objItem->{InputFrames}\n";
      print "InputTimeouts: $objItem->{InputTimeouts}\n";
      print "InputTransportErrors: $objItem->{InputTransportErrors}\n";
      print "InputWaitForOutBuf: $objItem->{InputWaitForOutBuf}\n";
      print "InputWdBytes: $objItem->{InputWdBytes}\n";
      print "InputWdFrames: $objItem->{InputWdFrames}\n";
      print "Name: $objItem->{Name}\n";
      print "OutputAsyncFrameError: $objItem->{OutputAsyncFrameError}\n";
      print "OutputAsyncOverflow: $objItem->{OutputAsyncOverflow}\n";
      print "OutputAsyncOverrun: $objItem->{OutputAsyncOverrun}\n";
      print "OutputAsyncParityError: $objItem->{OutputAsyncParityError}\n";
      print "OutputBytes: $objItem->{OutputBytes}\n";
      print "OutputCompressedBytes: $objItem->{OutputCompressedBytes}\n";
      print "OutputCompressFlushes: $objItem->{OutputCompressFlushes}\n";
      print "OutputCompressionRatio: $objItem->{OutputCompressionRatio}\n";
      print "OutputErrors: $objItem->{OutputErrors}\n";
      print "OutputFrames: $objItem->{OutputFrames}\n";
      print "OutputTimeouts: $objItem->{OutputTimeouts}\n";
      print "OutputTransportErrors: $objItem->{OutputTransportErrors}\n";
      print "OutputWaitForOutBuf: $objItem->{OutputWaitForOutBuf}\n";
      print "OutputWdBytes: $objItem->{OutputWdBytes}\n";
      print "OutputWdFrames: $objItem->{OutputWdFrames}\n";
      print "PageFaultsPersec: $objItem->{PageFaultsPersec}\n";
      print "PageFileBytes: $objItem->{PageFileBytes}\n";
      print "PageFileBytesPeak: $objItem->{PageFileBytesPeak}\n";
      print "PercentPrivilegedTime: $objItem->{PercentPrivilegedTime}\n";
      print "PercentProcessorTime: $objItem->{PercentProcessorTime}\n";
      print "PercentUserTime: $objItem->{PercentUserTime}\n";
      print "PoolNonpagedBytes: $objItem->{PoolNonpagedBytes}\n";
      print "PoolPagedBytes: $objItem->{PoolPagedBytes}\n";
      print "PrivateBytes: $objItem->{PrivateBytes}\n";
      print "ProtocolBitmapCacheHitRatio: $objItem->{ProtocolBitmapCacheHitRatio}\n";
      print "ProtocolBitmapCacheHits: $objItem->{ProtocolBitmapCacheHits}\n";
      print "ProtocolBitmapCacheReads: $objItem->{ProtocolBitmapCacheReads}\n";
      print "ProtocolBrushCacheHitRatio: $objItem->{ProtocolBrushCacheHitRatio}\n";
      print "ProtocolBrushCacheHits: $objItem->{ProtocolBrushCacheHits}\n";
      print "ProtocolBrushCacheReads: $objItem->{ProtocolBrushCacheReads}\n";
      print "ProtocolGlyphCacheHitRatio: $objItem->{ProtocolGlyphCacheHitRatio}\n";
      print "ProtocolGlyphCacheHits: $objItem->{ProtocolGlyphCacheHits}\n";
      print "ProtocolGlyphCacheReads: $objItem->{ProtocolGlyphCacheReads}\n";
      print "ProtocolSaveScreenBitmapCacheHitRatio: $objItem->{ProtocolSaveScreenBitmapCacheHitRatio}\n";
      print "ProtocolSaveScreenBitmapCacheHits: $objItem->{ProtocolSaveScreenBitmapCacheHits}\n";
      print "ProtocolSaveScreenBitmapCacheReads: $objItem->{ProtocolSaveScreenBitmapCacheReads}\n";
      print "ThreadCount: $objItem->{ThreadCount}\n";
      print "Timestamp_Object: $objItem->{Timestamp_Object}\n";
      print "Timestamp_PerfTime: $objItem->{Timestamp_PerfTime}\n";
      print "Timestamp_Sys100NS: $objItem->{Timestamp_Sys100NS}\n";
      print "TotalAsyncFrameError: $objItem->{TotalAsyncFrameError}\n";
      print "TotalAsyncOverflow: $objItem->{TotalAsyncOverflow}\n";
      print "TotalAsyncOverrun: $objItem->{TotalAsyncOverrun}\n";
      print "TotalAsyncParityError: $objItem->{TotalAsyncParityError}\n";
      print "TotalBytes: $objItem->{TotalBytes}\n";
      print "TotalCompressedBytes: $objItem->{TotalCompressedBytes}\n";
      print "TotalCompressFlushes: $objItem->{TotalCompressFlushes}\n";
      print "TotalCompressionRatio: $objItem->{TotalCompressionRatio}\n";
      print "TotalErrors: $objItem->{TotalErrors}\n";
      print "TotalFrames: $objItem->{TotalFrames}\n";
      print "TotalProtocolCacheHitRatio: $objItem->{TotalProtocolCacheHitRatio}\n";
      print "TotalProtocolCacheHits: $objItem->{TotalProtocolCacheHits}\n";
      print "TotalProtocolCacheReads: $objItem->{TotalProtocolCacheReads}\n";
      print "TotalTimeouts: $objItem->{TotalTimeouts}\n";
      print "TotalTransportErrors: $objItem->{TotalTransportErrors}\n";
      print "TotalWaitForOutBuf: $objItem->{TotalWaitForOutBuf}\n";
      print "TotalWdBytes: $objItem->{TotalWdBytes}\n";
      print "TotalWdFrames: $objItem->{TotalWdFrames}\n";
      print "VirtualBytes: $objItem->{VirtualBytes}\n";
      print "VirtualBytesPeak: $objItem->{VirtualBytesPeak}\n";
      print "WorkingSet: $objItem->{WorkingSet}\n";
      print "WorkingSetPeak: $objItem->{WorkingSetPeak}\n";
      print "\n";
   }
}