Script to execute a SQL query directly on the IVANTI database. PowerShell is used to connect and query the table.

For a simple table, use SSMS to identify tables. For complex queries, refer to: EPM: Transform a LANDESK query into a SQL query

$dataSource = "YourSQLServerName\Instance"
$user = "YourUsername"
$pass = 'YourPassword'
$database = "YourDatabaseName"

$connectionString = "Server=$dataSource;uid=$user; pwd=$pass;Database=$database;Integrated Security=False;"

$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()

$query = "SELECT * FROM [$database].[dbo].[YourTableName]"

$command = $connection.CreateCommand()
$command.CommandText = $query

$result = $command.ExecuteReader()

$table = New-Object System.Data.DataTable
$table.Load($result)

foreach ($row in $table) {
    Write-Host $row.ColumnName
}