07-28-2021 05:26 PM
07-29-2021 05:30 PM
Select Top 1000000
tblAssets.AssetID,
tblAssets.AssetName,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblADUsers.Displayname,
LogonHistory.LastLogon,
tsysIPLocations.IPLocation,
tblAssets.IPAddress,
tblAssetCustom.Custom2 As [ITSM User],
tblAssetCustom.Custom3 As [ITSM Status],
tblAssets.Lastseen,
tblCPlogoninfo.Username,
tblAssets.Username AS [Assets Username]
From
tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
LEFT Join (SELECT
tblCPlogoninfo.AssetID,
Max(tblCPlogoninfo.logontime) AS LastLogon
FROM
tblCPlogoninfo
GROUP BY
tblCPlogoninfo.AssetID) AS LogonHistory ON LogonHistory.AssetID = tblAssets.AssetID
Left Join tblCPlogoninfo ON tblCPlogoninfo.AssetID = tblAssets.AssetID AND tblCPlogoninfo.logontime = LogonHistory.LastLogon
Inner Join lansweeperdb.dbo.tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID
Left Join tblADUsers On tblADUsers.Userdomain = tblCPlogoninfo.Domain And tblADUsers.Username = tblCPlogoninfo.Username
Where tblAssets.AssetName Like 'z%'
Order By tblAssets.AssetName,
LastLogon Desc
07-29-2021 06:44 PM
07-29-2021 05:10 PM
07-29-2021 05:18 PM
RC62N wrote:
Drat. You're right: the logic is pulling the most recent logon for each user who's logged on to the machine. Let me rethink that...
07-29-2021 04:35 PM
Select Top 1000000
tblAssets.AssetID,
tblAssets.AssetName,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblADUsers.Displayname,
LogonHistory.LastLogon,
tsysIPLocations.IPLocation,
tblAssets.IPAddress,
tblAssetCustom.Custom2 As [ITSM User],
tblAssetCustom.Custom3 As [ITSM Status],
tblAssets.Lastseen,
LogonHistory.Username
From
tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
LEFT Join (SELECT
tblCPlogoninfo.AssetID,
Max(tblCPlogoninfo.logontime) AS LastLogon,
tblCPlogoninfo.Domain,
tblCPlogoninfo.Username
FROM tblCPlogoninfo
GROUP BY
tblCPlogoninfo.AssetID,
tblCPlogoninfo.Domain,
tblCPlogoninfo.Username) AS LogonHistory ON LogonHistory.AssetID = tblAssets.AssetID
Inner Join lansweeperdb.dbo.tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID
Left Join tblADUsers On tblADUsers.Userdomain = LogonHistory.Domain And tblADUsers.Username = LogonHistory.Username
Where tblAssets.AssetName Like 'z%'
Order By tblAssets.AssetName,
LastLogon Desc
07-29-2021 04:42 PM
07-28-2021 10:41 PM
LEFT JOIN tblADUsers ON tblADUsers.Userdomain = tblAssets.Userdomain AND tblADUsers.Username = tblAssets.Username
07-29-2021 12:52 PM
Thanks, that helps, but it still does not show computers that no one has logged into, or that the user login information is no longer in the Config/UserInfo/Lastlogon list because they have not logged in for a really long time. Here is the code that I have so far.
Select Top 1000000 tblAssets.AssetID,
tblAssets.AssetName,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblADUsers.Displayname,
Max(tblCPlogoninfo.logontime) As LastLogon,
tsysIPLocations.IPLocation,
tblAssets.IPAddress,
tblAssetCustom.Custom2 As [ITSM User],
tblAssetCustom.Custom3 As [ITSM Status],
tblAssets.Lastseen,
tblCPlogoninfo.Username
From tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tblCPlogoninfo On tblAssets.AssetID = tblCPlogoninfo.AssetID And
tblCPlogoninfo.Username = tblAssets.Username
Inner Join lansweeperdb.dbo.tsysIPLocations On tsysIPLocations.LocationID =
tblAssets.LocationID
Left Join tblADUsers On tblADUsers.Userdomain = tblAssets.Userdomain
And tblADUsers.Username = tblAssets.Username
Where tblAssets.AssetName Like 'z%'
Group By tblAssets.AssetID,
tblAssets.AssetName,
tsysAssetTypes.AssetTypeIcon10,
tsysIPLocations.IPLocation,
tblAssets.IPAddress,
tblAssetCustom.Custom2,
tblAssetCustom.Custom3,
tblAssets.Lastseen,
tblCPlogoninfo.Username,
tsysAssetTypes.AssetTypename,
tblAssets.Lasttried,
tblADUsers.Displayname
Order By tblAssets.AssetName,
LastLogon Desc
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now