Import external data in KQL
There are multiple ways on how you can import your asset management information: either from a CSV-File or from a SQL Table.
From CSV-File
let asset = externaldata (
Host:string, domain:string ) [@"https://raw.githubusercontent.com/flo7000/serverownervulnerabilitynotification/main/example.csv"
] with (ignoreFirstRecord=true);
asset
From SQL Table
# Convert-TableToKQLString is from my custom PowerShell Module
$sqlServerName = "yourDB.database.windows.net"
$sqlDatabaseName = "db01"
$sqlSelectQuery = "SELECT hostLookup, contact, oe FROM [dbo].[asset]"
$sqlAccessToken = (Get-AzAccessToken -ResourceUrl https://database.windows.net).Token
$table = Invoke-Sqlcmd -ServerInstance $sqlServerName -Database $sqlDatabaseName -Query $sqlSelectQuery -AccessToken $sqlAccessToken
if ($table.Rows.Count -eq 0) { Write-Output "No data found in SQL query. Exiting script."; exit }
$assetString = Convert-TableToKQLString -table $table -fields @('hostLookup', 'contact', 'oe')
$kqlQuery = @"
let asset = datatable(HostSrc: string, contact: string, oe: string)
[
$assetString
];
DeviceTvmSoftwareVulnerabilities
| extend HostSrc = replace_string(DeviceName, ".flo7000.ch", "")
| join kind=inner (asset) on HostSrc
...