10-22-2024 04:19 PM
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
Solved! Go to Solution.
10-23-2024 04:59 PM
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.
10-23-2024 07:33 PM
Ls doesn't have powershell module or api (only cloud version).
You can do direct sql query to ls database from powershell
10-31-2024 08:38 PM
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'"
10-23-2024 02:42 PM
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.