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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | $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 } |