r/Lansweeper • • Jul 12 '19

Lansweeper-PS Modules

TL;DR: Made some Powershell modules for querying LS data about assets and users. Hopefully it doesn't suck, view my Github here or install Lansweeper-PS from PSGallery and tell me what you think. Also if you can do it better than me, please contact me to contribute to the project.

Hey guys, I posted earlier this week wondering if there were any Powershell modules available to interact with the data in LS for automation purposes. After like....3 people seemed interested I decided to devote the week to learning the best way to create/publish the modules. This module uses dbatools (a nice little set of modules for working with SQL) to query the SQL server behind LS and return an object with all properties found for any given user/computer. Please view the Github readme for the brief requirements.

I am super new to Github and publishing to PSGallery, so any help is appreciated. If anybody is interested in contributing still please let me know and I can add you as a contributor on Github. TBH I've never made anything "for the community" before so I am just hoping it can be used and added to, honestly. Below are some screenshots.

13 Upvotes

7 comments sorted by

3

u/MadBoyEvo Jul 12 '19

Great work. A couple of tips

  1. I'm wondering if you should maybe work on the SQL part. You're doing a lot of joins on PowerShell from the tables which probably isn't the best, efficient way to do it. You may want to write a single SQL query with JOINS and readjust that into PS Object. Will save you some PowerShell work, will be much faster.

  2. You may want to split your module into Private/Public folder at some point and build on that. And then when publishing to PSGallery you just merge that in. I could probably show you how I publish my modules with another PowerShell module I wrote and it's effortless but it makes things easy to develop (as each function is in a separate file)

2

u/deanm11345 Jul 12 '19
  1. Where could I learn how to do this? My biggest challenge so far has been working with SQL, Powershell isn’t necessarily new to me but SQL absolutely is. I appreciate the tip a lot! I’m not gonna lie, most of my struggles were trying to form that query. So once I got one that worked consistently, I tired to spend time on the rest :)

  2. Will do! Once again, this was a new territory for me and one of the things I’d like to get down ASAP are the best practices.

2

u/MadBoyEvo Jul 14 '19

When I started responding to your query I came up with a really simple way to interact with Lansweeper in PS.

I'm using SQL that someone else produced on Lansweeper page (community / lansweeper as a vendor) and just prepared 70 lines of code to wrap this around into one command. You just drag and drop SQL code and it takes care of the rest. Hope you can "use it" to learn and expand on your idea, as surely more things could be done with Lansweeper.

Hope it gets useful to you.

2

u/deanm11345 Jul 12 '19

Also, if you are still interested in helping and out and wouldn’t mind showing me a few things, please DM me :)

1

u/MadBoyEvo Jul 13 '19

I don't like the DM option of Reddit, it's hard to help really that way. Probably PowerShell discord or similar would be better.