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

Basically, I want to run an SQL to auto-populate the tblAssetCustom.Contact  on what is in the Last User

 

mjdelacr_0-1660040462179.png

 

1 ACCEPTED SOLUTION
Bruce_B
Lansweeper Alumni

I've added a script below which fills the scanned AD displayname in the Contact field, if the last logged on user was an AD user and this AD user was scanned via an Active Directory User Path target.

  • Keep in mind that this script will overwrite any data that is currently already stored in tblAssetCustom.Contact, to avoid that, you'd need to adjust the where clause (only select rows with empty/NULL values in that field)
  • Do be careful when running scripts, make sure you've got a backup ready, just in case. Keep in mind you can no longer run scripts via the web console, this was removed to improve the security of the application. You'll need to connect to your Lansweeper database using SQL Server Management Studio or user Program Files (x86)\Lansweeper\Tools\DatabaseMaintenance.exe

https://www.lansweeper.com/kb/94/backing-up-your-installation.html

Keep in mind that joining tblADUsers to the script will likely reduce the amount of assets targeted by it. It should still cover all of your Windows computers that have had logons by AD users if you've fully scanned your AD via an AD User Path scanning target.

 

UPDATE tblassetcustom
  SET 
      contact = ad.Displayname
FROM tblassetcustom
     INNER JOIN tblassets a ON a.assetid = tblassetcustom.assetid
     INNER JOIN tbladusers ad ON ad.username = a.username
                                 AND ad.Userdomain = a.Userdomain;

 

 

View solution in original post

2 REPLIES 2
Bruce_B
Lansweeper Alumni

I've added a script below which fills the scanned AD displayname in the Contact field, if the last logged on user was an AD user and this AD user was scanned via an Active Directory User Path target.

  • Keep in mind that this script will overwrite any data that is currently already stored in tblAssetCustom.Contact, to avoid that, you'd need to adjust the where clause (only select rows with empty/NULL values in that field)
  • Do be careful when running scripts, make sure you've got a backup ready, just in case. Keep in mind you can no longer run scripts via the web console, this was removed to improve the security of the application. You'll need to connect to your Lansweeper database using SQL Server Management Studio or user Program Files (x86)\Lansweeper\Tools\DatabaseMaintenance.exe

https://www.lansweeper.com/kb/94/backing-up-your-installation.html

Keep in mind that joining tblADUsers to the script will likely reduce the amount of assets targeted by it. It should still cover all of your Windows computers that have had logons by AD users if you've fully scanned your AD via an AD User Path scanning target.

 

UPDATE tblassetcustom
  SET 
      contact = ad.Displayname
FROM tblassetcustom
     INNER JOIN tblassets a ON a.assetid = tblassetcustom.assetid
     INNER JOIN tbladusers ad ON ad.username = a.username
                                 AND ad.Userdomain = a.Userdomain;

 

 

mjdelacr
Engaged Sweeper II

I can confirm Script the worked! thanks a lot Bruce_B