Reporting PC status for the Computer Availability system

For anyone who follows the IT Services blogs you’ll already be aware of the newly launched Computer Availability system. If you haven’t already then I suggest you read this excellent post on the Web Services blog and then have a look at the actual system here

As the other blog already covered all the basics I really wanted to focus on what part Infrastructure Solutions had been able to play in the project. Most of our work was done in relation to reporting the status from each computer and helping to draw up an accurate representation of their locations.

For the later part we already had a fairly useful system in place for PC location, we’d been looking at creating a PC availability system for around 2 years so this was on our mind when we moved to Active Directory. At that time we implemented a quite robust naming convention for all PC areas around campus. By splitting computers up into specific areas we can deliver different group policies to them, this makes it very easy to offer up specific printers or software based on the location of a PC.

To understand how this works we’ll take a look at one of the areas, in this case the Library quiet study. From this area we will look at one PC, in this case UL2QS-12-10056. From the name we can tell the following information:

UL : University Library
2 : 2nd Floor
QS : Quiet Study
12 : the 12th PC in the area
10056 : Edge Hill hardware audit record 10056

As you can see in the screenshot below (click for big) we have similar names for each PC in the area, just with individual numbers and audits to mark them apart.

As you can imagine this information came in very useful when we started looking at a PC availability system. Immediately we could not only take the PC name and use it as a unique identifier but also tell roughly where the PC was located. From there it was a fairly simple case of working with Web Services to map the exact location of each computer onto the Library floor plan.

Once we had all of the computers mapped we then had to get them reporting their status. After a few different approached it was determined that Powershell would be the best option for this task. A repeating script running on each computer would put a tiny overhead on the machine while keeping the web site up to date. The script is very simple and will report the computer name and if a user is logged in or not. If the script isn’t reporting then the computer is switched off (so therefore available). We run the script in a loop that makes it report every 60 seconds, this way we can make sure that the information is no longer than a minute old (and hopefully pretty accurate!)

Here’s the powershell we are using, we use group policy to target specific areas to run the script.

$computername = “NONAME”
$domainusernametemp = “”
$domainusername = “NODOM”
$locked = “false”
$computername = gc env:computername
$domainusernametemp = Get-WMIObject Win32_Process -filter ‘name=”explorer.exe”‘ | ForEach-Object { $owner = $_.GetOwner(); ‘{0}\{1}’ -f $owner.Domain, $owner.User } | Sort-Object | Get-Unique
$domainusernametemp = $domainusernametemp -replace “\\”, “/”
if ($domainusernametemp) { $domainusername = $domainusernametemp } else { $domainusername = “NODOM/NOUSERNAME” }
if (Get-Process “LogonUI.exe” -ea SilentlyContinue) { $locked = “true” }
(new-object net.webclient).DownloadString(“https://website.goes.here/computers/update/$computername/$domainusername/$locked”)

We still need to work on another script so that we can monitor the status of Apple Macs. This will be a bit more complex as they dual boot both OS X and Windows 7 and we will need to perform more checks to determine their availability by querying both operating systems. Hopefully then we can expand the system to monitor the Hub!

About Stuart Gould

IT Services Senior Infrastructure Solutions Specialist. Microsoft Certified Solutions Expert: Private Cloud, MCSE: Windows Server 2003, MCSA: Windows Server 2012, Windows Server 2008, Window Server 2003, Windows 7
This entry was posted in Cool Stuff, Technical and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *