I can hear you asking – If Lansweeper is so great, why do you need to access it with PowerShell? Well, Lansweeper gathers a lot of data, lots of data that you usually have to spend time preparing in PowerShell thru different means, and that's not always the fastest way. Think of a situation where the manager asks you what version of Microsoft Office is on all computers or as in the example above BIOS version. Can you get that with PowerShell? Sure. But to get that you will have to scan every PC in your domain and that's not trivial because not all computers are online, at all times. But if you have Lansweeper, it already has that information. I can hear you saying again – But if you already have that report in Lansweeper, why need for PowerShell? Well, based on that Lansweeper report, I can do any action I want in PowerShell. Send an email, install new software, restart the computer, any activity that you can think of at your fingertips. Well sort of, because we have to get that SQL connection up and running first right? Since I had two „free” hours, I wrote a quick PowerShell Module called PSLansweeper which you can install straight from PowerShellGallery
This module has one command called Get-LansweeperReport working in two modes. First mode with three parameters – SQLInstance, Database (default: LansweeperDB) and Report allows you to get report content (you can ask multiple reports at the same time). Second mode is to list available reports with ListReports parameter.
You can query multiple reports at the same time and when you do that Hashtable of Arrays returns just like on the screenshot below. You can then pick the report output as you need.
You can choose from 20 or so Lansweeper reports that I have copied over from Lansweper website for testing purposes.
But since I didn't want to limit this module to only reports, I've picked, and reports that I will add when I will need something, you can add more reports yourself. The way it works is that the Reports parameter is dynamic. This means the list is built based on SQL files in three folders:
All you have to do is put SQL code in one of the folders, name file any way you want to with SQL extension.
The Report parameter will remove all spaces, remove all hyphens, and show you all reports together from all three folders. So whether you want to have BIOS information, or something entirely different, custom one, create new SQL file in the proper folder, add SQL Query in there, save and be ready to go.