cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Powershell module for Lansweeper - Automation

SubnetJO
Engaged Sweeper II
Goodmorning
In my company we are using Lansweeper.
I need to to automate some tasks basing on the Lansweeper assets.
At its basics, I need to query and filter lansweeper assets and perform some tasks on each filtered asset.


Is there any supported way to integrate Lansweeeper into automation?

I use powershell.
I have found a module on the Powershell Gallery: https://www.powershellgallery.com/packages/Lansweeper-PS/1.30.5

However, I cannot get it to work.

Could you please help me with this module?
How should be the get-LSasset command to get all the Assets object with all the properties

What I know is:
- Lansweeper server Ip address (and name)
- My username and password (I sucessfylly login and query assets on the web pages)

If you have different solution (python, .Net... whatever) please tell me.

Thank you for your kind help
6 REPLIES 6

uSlackr
Engaged Sweeper
I've been able to query lansweeper from powershell and have integrated it into several scripts. I use a couple components to make this work.
the
get-sql
module allows me make queries and the ReallySimpleDatabase allow me to move the results into an in-memory database for further queries. Here is some sample code

The way I use this is to call the function and assign the results to a $var. That $var is a ReallySimpleDatabase in-memory db. I then query that to pull the results. You could easily change the way it is used.


function Build-LSInfo {
#Grabs all assets in lansweeper with usernames defined
#stored in sqlite db
$sql = @"

Select Top 1000000 tblAssets.AssetID,
tblAssets.AssetName,
Convert(nvarchar(10),Ceiling(Floor(Convert(integer,tblAssets.Uptime) / 3600 /
24))) + ' days ' +
Convert(nvarchar(10),Ceiling(Floor(Convert(integer,tblAssets.Uptime) / 3600 %
24))) + ' hours ' +
Convert(nvarchar(10),Ceiling(Floor(Convert(integer,tblAssets.Uptime) % 3600 /
60))) + ' minutes' As UptimeSinceLastReboot,
tblAssets.Lastseen,
tblAssets.Username,
tblAssets.IPAddress,
tblAssetCustom.Manufacturer,
tblAssetCustom.Model,
Coalesce(tsysOS.OSname, tblLinuxSystem.OSRelease, tblMacOSInfo.SystemVersion)
As OS
From tblAssets
Left Join tsysOS On tsysOS.OScode = tblAssets.OScode
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID
Inner Join tblState On tblState.State = tblAssetCustom.State
Left Join tblLinuxSystem On tblAssets.AssetID = tblLinuxSystem.AssetID
Left Join tblMacOSInfo On tblAssets.AssetID = tblMacOSInfo.AssetID

Where (tblAssets.Lastseen > GetDate() - 30 And tblAssets.Domain = 'OURDOMAIN'
And tblAssets.Lasttried > GetDate() - 45) Or
(tblAssets.Uptime Is Not Null And tblAssets.Domain = 'OTHERDOMAIN' And
tblState.Statename = 'Active')
Order By tblAssets.Uptime Desc,
tblAssets.AssetName,
tblAssets.IPNumeric
"@
$db_x = $null
$db_x = get-database #creates an in-memory db using ReallySimpleDatabase (see docs for using an on-disk db)
#queries the lansweeper db defined in the connection string; session stored in "TT"
$hld = get-sql -MsSQLserver -connection "Server=lansweeper.myco.com;Integrated Security=true;Initial Catalog=lansweeperdb;ApplicationIntent=ReadOnly" -Session TT
#Sends the results of the query to the sqllite db using import-db - creates LSU table
TT $SQL |import-database -database $db_x -tablename LSU
#$db_x = TT $SQL
#closes the session TT
TT -close
#returns the in-memory db
return $db_x
}

SubnetJO
Engaged Sweeper II
Goodevenig
One year is passed since my original question about the availability of a powershell module for Lansweeper.
I still have the same need but one of the first links out of my google search are about this post.

As far as you know, has Lansweeper development team created a module for powershell?
Is there an API, or the web interface is the only way we can access lansweeper?

Thank you for your help

Hendrik_VE
Champion Sweeper II
We are using a similar approach in our environment to test the VNC connection to a dynamic list of Workstations using PowerShell.
How we do it is like this:
1. Daily export the list (based on a custom filter) of Workstations to a csv file
2. Scheduled Posh script imports the csv, executes a command to test the VNC port and sends the result to a mail recipient.


Importing the csv is done by this command:
import-csv -delimiter ';' -path "C:\Program Files (x86)\Lansweeper\Service\export\VNC-check.csv"

Testing the port is done by this command:
new-object System.Net.Sockets.TcpClient($rh, $p)

ufficioced
Champion Sweeper
SubnetJO wrote:
Goodmorning
I need to to automate some tasks basing on the Lansweeper assets.
At its basics, I need to query and filter lansweeper assets and perform some tasks on each filtered asset.


I don't know if I understood your problem

You could use "deploy package" in Lansweeper web console: create a deploy package with the configuration you need and then a report filtering the right assets

in the report's asset list you can deploy the package to the assets

let me know, regards

SubnetJO
Engaged Sweeper II
ufficioced wrote:
SubnetJO wrote:
Goodmorning
I need to to automate some tasks basing on the Lansweeper assets.
At its basics, I need to query and filter lansweeper assets and perform some tasks on each filtered asset.


I don't know if I understood your problem

You could use "deploy package" in Lansweeper web console: create a deploy package with the configuration you need and then a report filtering the right assets

in the report's asset list you can deploy the package to the assets

let me know, regards



Thank you for your kind answer
However, what I need is to query lansweeper programmatically, hopefully integrating with a powershell.

Let's say I want to know how many IP Locations with a name that starts with "XYZ" I have, and then doing something elsewhere basing on the result.

For example I have a list of licenses assigned to each IP Location.
I need to check if we have licenses still assigned to no longer existing sites.
So I need to compare the list of the licenses and the list of the alive sites.
Where I can get the list of the alive sites?
I'm told "look at the IP locations in lanswepeer".

So, since my scripts are powershell, my question is: how can I query Lansweeper by powershell?
I know of the "unofficial" module, I tried it, but I cannot get it to work.

Is there something Official?
Is there any programmatical way to query Lansweeper, without querying the undergoing database directly, of course

Thank you for your kind help

SubnetJO wrote:

So, since my scripts are powershell, my question is: how can I query Lansweeper by powershell?
...
Is there any programmatical way to query Lansweeper, without querying the undergoing database directly, of course


You need an API but as far as I know is under deployment in Lansweeper.
I think you can use a different approach with reports (exporting for example in Excel) and deployments, but I don't really know your configuration so I can't assure you this is the right way.