→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
KelKoop
Engaged Sweeper II

I'm working on some PowerShell scripts and it would be handy if I could look up a User's computer name from LanSweeper.

Is there a simple way to do this?

Thanks!
—Kel

2 ACCEPTED SOLUTIONS
FrankSc
Lansweeper Tech Support
Lansweeper Tech Support

In Lansweeper, all data is stored in the SQL Server database.
If you are able to read from the database, with powershell, this may work.

View solution in original post

Ls doesn't have powershell module or api (only cloud version).

You can do direct sql query to ls database from powershell 

View solution in original post

9 REPLIES 9
Josha
Engaged Sweeper III

In my environment, the Lansweeper database is stored in MSSQL.  I installed the SQL Server PowerShell module and use it to directly interact with the SQL database. 

Once the module is installed, you can use a command like the one below ran from a user's workstation to get their assets.  I don't think this is the best way to achieve this goal though as you'd have to install the SqlServer module on every endpoint and then you'd have to leave credentials on the machines to access it.

If you must use a script that runs from the user's machine, I'd recommend setting up a scheduled task on a server that exports a CSV to a file share every 10 minutes using the SqlServer module and a SQL query.  The query could get all unique assets by name and the user associated with it.  Then the script you're running on the client workstations can simply access the CSV and it will refresh every 10 minutes.

What exactly are you trying to accomplish? 

# Get User name from WMI
$userName = Get-CimInstance -ClassName win32_computersystem | Select -ExpandProperty Username

# Remove Domain name from string if it exists
if ($userName -like '*\*'){
    $userName = ($userName -split '\\')[1]
    }

# Get Asset name from user
$assetName = Invoke-Sqlcmd -ServerInstance LANSWEEPSERVER\LANSWEEPER -Database lansweeperdb -ConnectionTimeout 30 -QueryTimeout 300 -Username "abcdefgh" -Password "12345678" -Query "SELECT AssetName FROM tblAssets where username = '$userName'"

 

KelKoop
Engaged Sweeper II

Thanks, Frank.  I am aware I can query the %machineName% variable from the OS at the computer.  What I was hoping for is to pull the comuputer from the User's LanSweeper page so I know what machine he last logged into even if he's not active. 

Mister_Nobody
Honored Sweeper II

We have action with powershell call

action code:

powershell.exe -version 2 -exec bypass -windowstyle hidden -command "\\LS_server_name\lansweeper$\Name.ps1" {username}

{assetname} for computer

into posh:

Param(
[string]$username,
[String]$machine
)

 

 

Thanks, Mister.  It appears that our Lansweeper host does not have Name.ps1.   In the share lansweep$ I see some .dll, executables and VB scripts.  Nothing PowerShell.

You have to write own powershell code! 

not helpful.  I write PS code a lot.  Some info on Lansweeper specifically is what I was hoping for. 

Ls doesn't have powershell module or api (only cloud version).

You can do direct sql query to ls database from powershell 

FrankSc
Lansweeper Tech Support
Lansweeper Tech Support

In Lansweeper, all data is stored in the SQL Server database.
If you are able to read from the database, with powershell, this may work.

FrankSc
Lansweeper Tech Support
Lansweeper Tech Support

Dear, 

There could be different ways to achieve this. But we believe it will be better to look into Powershell resources or documentation for that. I found the link below as an example:
PowerTip: Use PowerShell to Get Computer Name - Scripting Blog [archived]