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.
a month ago
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.
a month ago
Ls doesn't have powershell module or api (only cloud version).
You can do direct sql query to ls database from powershell
3 weeks ago
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'"
a month ago
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.
a month ago
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
)
a month ago
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.
a month ago
You have to write own powershell code!
a month ago
not helpful. I write PS code a lot. Some info on Lansweeper specifically is what I was hoping for.
a month ago
Ls doesn't have powershell module or api (only cloud version).
You can do direct sql query to ls database from powershell
a month ago
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.
a month ago
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]
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now