About Me · Send mail to the author(s) E-mail · Twitter

At GROSSWEBER we practice what we preach. We offer trainings for modern software technologies like Behavior Driven Development, Clean Code and Git. Our staff is fluent in a variety of languages, including English.

Feed Icon


Open Source Projects


Blogs of friends

Now playing [?]

Error retrieving information from external service.


Enumerating Foreign Interactive Sessions in Powershell

Posted in PowerShell at Friday, 13 April 2007 17:40 W. Europe Daylight Time

A reader asked if it is possible to get all interactive sessions not created by the current user (i.e. the Administrator) in Powershell. Since I had done something similar in my Terminal Server logon script some time ago I thought this would be pretty easy to achieve. Again, I'm heavily relying on WMI. Yet, handling the "flat" (in an OO sense) WMI objects mostly containing string properties doesn't seem right. Here's what I came up with:

# Prints the number of interactive sessions not created by the current user.

$CurrentUserFragment = "*Domain=`"" + $Env:UserDomain.Trim() + "`",Name=`"" + $Env:Username.Trim() + "`""

# Get all interactive sessions (including Terminal Server sessions).
$InteractiveSessions = Get-WmiObject Win32_LogonSession | Where-Object {
    $_.LogonType -eq 2 -or $_.LogonType -eq 10

$ForeignSessions = 0
foreach($Session in $InteractiveSessions) {
    $SessionIdFragment = "*`"" + $Session.LogonId + "`""
    # Test if the session is established by the current user.
    $ForeignSession = Get-WmiObject Win32_LoggedOnUser | Where-Object {
        $_.Antecedent -inotlike $CurrentUserFragment -and $_.Dependent -ilike $SessionIdFragment
    } | Measure-Object
    $ForeignSessions += $ForeignSession.Count

Write-Host $ForeignSessions "Foreign Interactive Session(s)"

This command basically mimics this UNIX command supplied by the reader¹:

who | grep -V "root" | wc -l

The Powershell script is not as concise as I would like it to be and presumably could be optimized. My quick hack should be wrapped in a Cmdlet if you plan to use it in a professional environment.

¹ I have no idea if the script works because I didn't test it. 

Now Playing [?]: Thievery CorporationThe Cosmic GameDoors of perception (feat. Gunjan)

Monitoring Servers

Posted in Networking at Friday, 06 April 2007 17:18 W. Europe Daylight Time

In case you own a server that is located in your apartment or is hosted at a professional data center, you might find it interesting to know how the server's tasks and services affect the overall load. Load is what you pay for in regard to the hosting provider and it's desirable to have an eye on the server performance.

Of course you could RDP into the server and start up the task manager or the performance monitor. However, this will only give you an impression of the current load. Perfmon is able to record statistics of various performance counters, but downloading the logs and analyzing them locally is quite a hassle. Also, you will have to repeatedly download and analyze logs in order to get an impression how the counter values evolve over time.

What about a easy solution that leverages standards and renders nice graphs? I use MRTG by Tobi Oetiker to monitor some performance counters of the (two) servers I'm in charge of. MRTG, a mature and free addition to the administrator's toolbox, uses SNMP and is able to generate graphs and web sites. Needless to say that MRTG is not targeted to replace advanced approaches to server management like SMS or MOM.

In order to give you an impression what can be achieved with MRTG, take a look at the following screenshot of a web site. The aggregated graphs you see show the activity of our home server over the last 24 hours.

MRTG Aggregate View

A click on any of daily graphs reveal a detailed view depicting the values of the selected counter up to over the last year. See how memory consumption steadily rises?

MRTG Detail View

MRTG is also good for finding temporary problems with server services. If you monitor HTTP connections and find that they come to a grinding halt, chances are that the web server has been running into problems. Of course, an enterprise-ready server monitoring solution would have sent out a notification about the problem in this case.

As said above, MRTG uses SNMP to get its data. However, finding the right SNMP OIDs for the counters you're interested in can be a complicated task because of the hierarchical nature of OIDs. MRTG can also run custom scripts (Batch, WSH, PowerShell, …) to acquire counter data, so you could query WMI (thus, also Windows performance counters), custom log files or any other data source. In this respect, MRTG is pretty powerful.

Data points are stored in log files that virtually newer grow because old data will be coalesced over time. The files take up about 55 KB for each counter on the machine above. Of course, this results in less accuracy for data from weeks ago, but generating 10000-foot-level graphs from these values is perfectly okay.

One tenable drawback of MRTG is that it's only able to acquire data points in 5-minute intervals. To get a higher temporal resolution choose RRDtool by the same author along with any supported application.

In order to get you started with MRTG here are some useful links for installing MRTG on your server:

Now Playing [?]: KoopKoop IslandsLet's elope

The Boy With The Incredible Brain

Posted in General at Sunday, 01 April 2007 16:25 W. Europe Daylight Time

Torsten pointed me to a video about an English boy with incredible mental capabilities. For example, Daniel Tammet is able to recall 22514 decimal places of the number π (a very beautiful number to his mind) envisioning some kind of landscape that's unique to this number, mentally connecting properties of the landscape to actual digits. At the end of the video he's learning Icelandic in just one week and puts his knowledge to the test in a TV show.

Absolutely amazing! 

Now Playing [?]: Kaiser ChiefsYours truly, angry mobRuby