Automating Lanschool deployment and setting channel with Powershell

lanschool-powershell

We use Lanschool as our classroom management software and as part of our Windows 7 deployment needed to reinstall the client on all our re-imaged desktops. In the past this was done manually by visiting each room after the OS had been installed. This time round I wanted to try and remove the manual work and find an automated method instead – the installation itself is bread and butter MSI silent install, however setting the correct channel for each room was slightly more challenging.

If you’re reading this you already know that Lanschool uses “channels” to decide which PCs are controlled by the teacher machine in the room. The problem for us was that Lanschool uses purely numeric notation for this whereas our rooms are a mix of letters and numbers.

Having sat down for a while trying to figure out a formula or numbering convention it was soon obvious that method wouldn’t work… back to the drawing board! The next idea I had was to create some sort of lookup table containing all our classroom names and then assign a unique channel for each one, easy enough with Excel auto-fill 😉

After a couple of minutes I had a suitable listing created and saved in CSV format as I figured it would be the easiest format to work with, now onto the Powershell. Initially I wasn’t sure how to read the file but after a bit of Googling found what I was looking for, the aptly named import-csv function. I specified the header values here rather than in the CSV file itself to keep the source data as simple as possible. The last part of the code grabs the channel number for whatever value resides in the variable named $WorkStationRoom

$channelvar = Import-Csv C:\setchannel\lanschool.csv -Header Room,Channel | Where-Object {$_.Room -eq $WorkstationRoom } | Select-Object Channel
$channel = $channelvar.channel

Because I base the script around the location of the machine I’d already read this into the $WorkstationRoom variable by grabbing it from a custom location I make in the registry during our naming process while imaging. To read the registry use the Get-ItemProperty function. Obviously how you get this data will depend on your naming convention and \ or what data you have available on the machine to get the room number from but the example below should give an idea of how it’s done.

$RegWorkstationRoom = Get-ItemProperty -path "HKLM:\Software\HCFHE" -name "WorkstationRoom"
$WorkstationRoom = $RegWorkstationRoom.WorkstationRoom

At one point I wondered if I was going about actually getting a value in a clunky way as I always needed the second line, however it does seem to be the right thing to do. There’s a better explanation of why on this thread (see the post by the user named Graimer)

“First we get an object containing the property we need with Get-ItemProperty and then we get the value of for the property we need from that object. That will return the value of the property as a string.”

Now we have our channel number we need to set it, fortunately Lanschool provide a utility called setchannel.exe that does exactly what it says on the tin! It can be found in the utilities folder of the Lanschool install files. More info on page 29 of the Lanschool manual. Call it from Powershell like this, using the WaitForExit method as it takes a few seconds to process the channel change…

$ChannelCommand = "C:\setchannel\setchannel.exe"
$process = [Diagnostics.Process]::Start($ChannelCommand,$channel)
$process.WaitForExit()

To build some validation into the process I check to see if there actually is a value in the $WorkStationRoom variable before running setchannel. If the variable comes back with a null value I set the channel to an arbitrary value I don’t use elsewhere (in this example 999). I can then use ZCM to query the channel value stored in the registry in HKLM\Software\Lanschool\Channel to find any machines that haven’t got a “proper” value set.

Note: you’ll need to check for this as any machines that get set to the “failed” channel number will all be controlled together, regardless of where they are!

if (!$channel)  {
    Write-Host "*** ROOM NAME INVALID ***"
    Write-Host "Quit imaging, check room name and restart"
    Write-Host "channel number set to 999"
    $channel = 999
} else {
    write-host $channel
     }

To finish off the installation make a quick update the registry to disable the annoying “would you like to register Lanschool?” dialog box that insists on popping up at every boot.

Use your preferred method of updating registry entries (in our case it was an action in the ZCM Bundle) to change the teacher.exe entry in HKLM\Software\Microsoft\Windows\CurrentVersion\Run to add the IgnoreRegPrompt parameter at the end of the executable path…

C:\Program Files\LanSchool\teacher.exe IgnoreRegPrompt

When done go to the teacher PC, hover over the Lanschool icon in the system tray and you should see the channel number from the input file in the popup panel… ans there you have it, zero-touch Lanschool deployment that works a treat 🙂

Advertisements

2 Responses to Automating Lanschool deployment and setting channel with Powershell

  1. G says:

    How can I get in touch with the author?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: