Configuring a scanning server through the web console takes many steps: server options, scanning targets, Active Directory scanning, Asset Radar, an LsAgent group, and an IP location. If you set up scanning servers regularly, you can do all of it in one pass by running a single script against the Lansweeper database.
This article covers one scanning server. To configure many servers at once, see Bulk-configure scanning servers with a SQL script. To only add IP ranges and map credentials to them, see Add IP ranges and map credentials with a SQL script.
Writing directly to the Lansweeper database bypasses the web console and can break your installation if a value is wrong. Back up your database before you continue, as explained in Back up your installation. Test the script on a non-production installation first.
Prerequisites
- The scanning server is installed and linked to the same database, and its service has started at least once. The script configures the server's existing database record, so that record must already exist.
- You have access to the SQL Server instance that hosts the
lansweeperdbdatabase, and SQL Server Management Studio to run queries. - You know the scanning server's name, IP range, domain details, and preferred domain controller.
What the script configures
Running the script once sets all of the following for a single scanning server:
- Scan server options (cleanup, active scanning, renamed computer detection, and Asset Radar settings), and marks the server active.
- Active Directory scanning for the server.
- An IP range scanning target, plus the scan server's own IP address as a target.
- An Active Directory domain and user path scanning target.
- A preferred domain controller.
- Asset Radar on the scan server's network interface.
- An LsAgent group with the scan server and a failover server.
- An IP location that matches the IP range.
Set your scan server details
Before running the script, replace the example values in the SET block with your own. Only these variables need editing; the rest are derived automatically.
| Variable | Example | What to enter |
|---|---|---|
@scannerName |
MYSCANSERVER01 |
The scanning server's name, exactly as it appears in the web console. |
@scannerDescription |
MY-IP-LOCATION-EMEA-BELGIUM-01 |
A label used as the name of both the IP location and the LsAgent group. |
@scannerStartIP |
10.0.0.0 |
First IP address of the range this server scans. |
@scannerEndIP |
10.0.0.255 |
Last IP address of the range this server scans. |
@scanServerIP |
10.0.0.254 |
The scanning server's own IP address. Used for the Asset Radar interface and as a single-IP target. |
@domainControllerName |
MYDOMAINCONTROLLER01 |
Hostname of the preferred domain controller, without the domain suffix. |
@domainNETBiosName |
MYDOMAIN |
The domain's NetBIOS (short) name. |
@domainDNSSuffix |
local |
The domain's DNS suffix, for example local or com. |
@iprangeStartTime |
14:00:00.000 |
Daily start time for the IP range scan. |
@domainUserPathStartTime |
11:00:00.000 |
Daily start time for the Active Directory user path scan. |
@scannerNameAsSecondaryLsAgentScanServer |
MYSCANSERVER02 |
A second scanning server to add to the LsAgent group for failover. |
@ignoreWindowsDuringIPRangeScan |
1 |
Set to 1 to skip Windows computers during IP range scanning, or 0 to include them. |
Run the script
- Stop the Lansweeper Server service on the scanning server. The service caches its configuration, so it needs to restart to pick up direct database changes.
- Open SQL Server Management Studio and connect to the SQL Server instance that hosts the
lansweeperdbdatabase. - Open a New Query window, paste the script below, and replace the example values in the
SETblock with your own. - Run the script.
- Start the Lansweeper Server service again.
USE [lansweeperdb]
GO
-- Variables
DECLARE
@scannerName NVARCHAR(100)
,@scannerStartIP NVARCHAR(50)
,@scannerEndIP NVARCHAR(50)
,@scanServerIP NVARCHAR(50)
,@domainNETBiosName NVARCHAR(380)
,@domainDNSSuffix NVARCHAR(10)
,@domainControllerFQDN NVARCHAR(100)
,@ipLocation NVARCHAR(50)
,@scannerDescription NVARCHAR(100)
,@lsAgentGroup NVARCHAR(100)
,@domainControllerName NVARCHAR(100)
,@domainDNSName NVARCHAR(100)
,@iprangeStartTime NVARCHAR(30)
,@domainUserPathStartTime NVARCHAR(30)
,@scannerStartIPNumeric NVARCHAR(30)
,@scannerEndIPNumeric NVARCHAR(30)
,@LsAgentGroupUID uniqueidentifier
,@scannerNameAsSecondaryLsAgentScanServer NVARCHAR(30)
,@ignoreWindowsDuringIPRangeScan INT
-- Replace the example values below with your own scan server details
SET @scannerName = N'MYSCANSERVER01'
SET @scannerDescription = N'MY-IP-LOCATION-EMEA-BELGIUM-01'
SET @scannerStartIP = N'10.0.0.0'
SET @scannerEndIP = N'10.0.0.255'
SET @scanServerIP = N'10.0.0.254'
SET @domainControllerName = N'MYDOMAINCONTROLLER01'
SET @domainNETBiosName = N'MYDOMAIN'
SET @domainDNSSuffix = 'local'
SET @iprangeStartTime = N'14:00:00.000'
SET @domainUserPathStartTime = N'11:00:00.000'
SET @scannerNameAsSecondaryLsAgentScanServer = N'MYSCANSERVER02'
SET @ignoreWindowsDuringIPRangeScan = 1
-- Derived values (no need to edit)
SET @scannerStartIPNumeric = PARSENAME(@scannerStartIP,4) +
REPLICATE('0',3-LEN(PARSENAME(@scannerStartIP,3))) + PARSENAME(@scannerStartIP,3) +
REPLICATE('0',3-LEN(PARSENAME(@scannerStartIP,2))) + PARSENAME(@scannerStartIP,2) +
REPLICATE('0',3-LEN(PARSENAME(@scannerStartIP,1))) + PARSENAME(@scannerStartIP,1)
SET @scannerEndIPNumeric = PARSENAME(@scannerEndIP,4) +
REPLICATE('0',3-LEN(PARSENAME(@scannerEndIP,3))) + PARSENAME(@scannerEndIP,3) +
REPLICATE('0',3-LEN(PARSENAME(@scannerEndIP,2))) + PARSENAME(@scannerEndIP,2) +
REPLICATE('0',3-LEN(PARSENAME(@scannerEndIP,1))) + PARSENAME(@scannerEndIP,1)
SET @domainDNSName = @domainNETBiosName + '.' + @domainDNSSuffix
SET @domainControllerFQDN = @domainControllerName + '.' + @domainNETBiosName + '.' + @domainDNSSuffix
SET @ipLocation = @scannerDescription
SET @lsAgentGroup = @scannerDescription
-- Configure scan server options and mark the server active
UPDATE [dbo].[tsysASServers] SET [IsAssetRadarCompatible] = 1, [IsAssetRadarEnabled] = 2, [ScanLastLogon] = 1, [SADDCOMP] = 0, [SADDUSER] = 0, [REFRADCOMP] = 1, [REFRADUSERS] = 1, [MAKEACTIVE] = 1, [NACOMP] = 1, [NACOMPDAYS] = 60, [DELCOMP] = 1, [DELCOMPDAYS] = 180, [NonActiveAssetRadarComp] = 1, [NonActiveAssetRadarCompDays] = 30, [DelAssetRadarCompUnknownOnly] = 1, [DelAssetRadarCompUnknownOnlyDays] = 30, [NADICOMP] = 1, [renamedComputerDetection] = 1, [RenamedComputerDetectionWithoutMac] = 1, [DoFallbackScanning] = 0 WHERE [Servername] = @scannerName
-- Configure Active Directory scanning
IF NOT EXISTS (SELECT LdapServerId FROM [dbo].[tsysLdapConfigurationServer] WHERE [ServerName] = @scannerName)
BEGIN
INSERT INTO [dbo].[tsysLdapConfigurationServer] ([LdapId],[ServerName],[LdapStatus],[LdapError],[LdapsStatus],[LdapsError],[LastStatusCheck])
VALUES (1,@scannerName,0,NULL,0,NULL,NULL)
END
-- Add the IP range scanning target
INSERT [dbo].[tsysIPScanRanges] ([Servername], [Ipstart], [Ipend], [Enabled], [PingTimeout], [IPIgnoreWindows], [DontPing], [Day1], [Day2], [Day3], [Day4], [Day5], [Day6], [Day7], [Day1time], [Day2time], [Day3time], [Day4time], [Day5time], [Day6time], [Day7time], [LastIPscan], [NoSSH], [Recurring], [Minutes], [Waittime], [SSHport], [SavePingedIP], [IPIgnoreKnownWindows], [Description], [SIPport], [ScanNow], [CloudId]) VALUES
(@scannerName, @scannerStartIP, @scannerEndIP, 1, 2, @ignoreWindowsDuringIPRangeScan, 0, 1, 1, 1, 1, 1, 1, 1, CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), NULL, 0, 0, 0, 1, 22, 1, 0, NULL, 5060, 0, NULL)
-- Add the scan server's own IP address as a target
INSERT [dbo].[tsysIPScanRanges] ([Servername], [Ipstart], [Ipend], [Enabled], [PingTimeout], [IPIgnoreWindows], [DontPing], [Day1], [Day2], [Day3], [Day4], [Day5], [Day6], [Day7], [Day1time], [Day2time], [Day3time], [Day4time], [Day5time], [Day6time], [Day7time], [LastIPscan], [NoSSH], [Recurring], [Minutes], [Waittime], [SSHport], [SavePingedIP], [IPIgnoreKnownWindows], [Description], [SIPport], [ScanNow], [CloudId]) VALUES
(@scannerName, @scanServerIP, @scanServerIP, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), CAST(N'1900-01-01T'+@iprangeStartTime AS DateTime), NULL, 0, 0, 0, 1, 22, 1, 0, NULL, 5060, 0, NULL)
-- Add the Active Directory domain
INSERT INTO [dbo].[tsysASDomains] ([Servername],[Domainname],[Netbiosname],[Description],[ScanNow],[LastScanned],[Enabled],[ErrorText],[CloudId],[IntervalInSeconds],[MinRescanTimeInSeconds],[MaxRescanTimeInSeconds]) VALUES
(@scannerName, @domainDNSName, @domainNETBiosName, null, 0, null, 1, '', null, 900, 72000, 172800)
-- Add the Active Directory user path
INSERT INTO [dbo].[tsysUserSchedule] ([Servername],[Scantarget],[Netbiosdomain],[Enabled],[ScanNow],[Day1],[Day2],[Day3],[Day4],[Day5],[Day6],[Day7],[Day1time],[Day2time],[Day3time],[Day4time],[Day5time],[Day6time],[Day7time],[LastScanned],[Description],[ErrorText],[CloudId]) VALUES
(@scannerName, N'dc='+@domainNETBiosName+',dc='+@domainDNSSuffix, @domainNETBiosName, 1, 0, 1, 1, 1, 1, 1, 1, 1, CAST(N'1900-01-01T'+@domainUserPathStartTime AS DateTime), CAST(N'1900-01-01T'+@domainUserPathStartTime AS DateTime), CAST(N'1900-01-01T'+@domainUserPathStartTime AS DateTime), CAST(N'1900-01-01T'+@domainUserPathStartTime AS DateTime), CAST(N'1900-01-01T'+@domainUserPathStartTime AS DateTime), CAST(N'1900-01-01T'+@domainUserPathStartTime AS DateTime), CAST(N'1900-01-01T'+@domainUserPathStartTime AS DateTime), NULL, NULL, NULL, NULL)
-- Add the preferred domain controller
INSERT INTO [dbo].[tsysDomainControllers] ([Servername],[DomainNetbios],[DomainControllerDns]) VALUES
(@scannerName, @domainNETBiosName, @domainControllerFQDN)
-- Enable Asset Radar on the scan server's network interface
UPDATE tsysInitialNetworkInterfaces SET [EnabledForAssetRadar] = 1 WHERE [Scanserver] = @scannerName AND [IPMachine] = @scanServerIP
UPDATE tsysInitialNetworkInterfaces SET [EnabledForAssetRadar] = 0 WHERE [Scanserver] = @scannerName AND [IPMachine] <> @scanServerIP
-- Create the LsAgent group with the scan server and a failover server
SET @LsAgentGroupUID = NEWID()
INSERT [tblLsAgentGroup] ([LsAgentGroupID],[Name],[Default],[Created],[LastChanged],[ScheduleID],[Status],[AutoUpdate])
VALUES (@LsAgentGroupUID,@lsAgentGroup,0,GETDATE(),GETDATE(),-2,1,1)
INSERT INTO [dbo].[tblLsAgentGroupUrl] ([SortOrder], [LsAgentGroupID], [ServerName]) VALUES (1, @LsAgentGroupUID, @scannerName)
INSERT INTO [dbo].[tblLsAgentGroupUrl] ([SortOrder], [LsAgentGroupID], [ServerName]) VALUES (2, @LsAgentGroupUID, @scannerNameAsSecondaryLsAgentScanServer)
-- Configure the IP location
INSERT INTO [dbo].[tsysIPLocations] ([StartIP],[EndIP],[IPLocation],[Realstart],[Realend],[PackageShare],[ShareUsername],[SharePassword],[ShareKeyHash],[CloudId])
VALUES (@scannerStartIPNumeric,@scannerEndIPNumeric,@ipLocation,@scannerStartIP,@scannerEndIP,'','','',NULL, NULL)
GO
Verify the configuration
After the service restarts, confirm the configuration in the web console:
- Go to Configuration > Server options and check the scanning server's settings.
- Go to Scanning > Scanning targets and confirm the IP range, the scan server's IP, the Active Directory domain, and the user path are listed.