Connection String for quering an odbc AS400 database via powershell:
$query = "SELECT * FROM my_table"
$conn = New-Object System.Data.Odbc.OdbcConnection
$conn.ConnectionString = "Driver={iSeries Access ODBC Driver};System=my-as400-server;Uid=User;Pwd=Password;"
$conn.Open()
$cmd = New-Object System.Data.Odbc.OdbcCommand($query, $conn)
$cmd.CommandTimeout = 15
$ds = New-Object system.Data.DataSet
$da = New-Object system.Data.odbc.odbcDataAdapter($cmd)
[void]$da.fill($ds)
$conn.close()
$result = $ds.tables[0]
foreach ($Row in $ds.Tables[0].Rows) {
write-Output "$($Row.field1)"
write-Output "$($Row.field2)"
}
Recent Comments