powershell to connect to sybase ASE

  • Hi All,

    I am stumbling on how to connect to SybaseASE and get data out using powershell.

    I came across this http://techjunkie.tv/connect-to-sybase-using-powershell

    and it works fine.

    $query="select * from syslogins"

    $conn=New-Object System.Data.Odbc.OdbcConnection

    $conn.ConnectionString= "driver={Adaptive Server Enterprise};dsn=SERVER_NAME;db=master;na=IP,PORT;uid=SOMEUSER;pwd=******;"

    $conn.open()

    $cmd=new-object System.Data.Odbc.OdbcCommand($query,$conn)

    $cmd.CommandTimeout=30

    write-host $query

    $ds=New-Object system.Data.DataSet

    $da=New-Object system.Data.odbc.odbcDataAdapter($cmd)

    write-host $ds

    $da.fill($ds)

    $ds.Tables[0] | out-gridview

    $conn.close()

    This gives a grid, but I want to have the output on the powershell window/screen.

    Also want to pipe that output to a sql table.

    Any one have idea how to do that .

    I am using Powershell v2 and ASE 15.03

    ______________________________________________________________________________________________________________________________________________________________________________________
    HTH !
    Kin
    MCTS : 2005, 2008
    Active SQL Server Community Contributor 🙂

  • Try replacing $ds.Tables[0] | out-gridview with

    foreach ($dataRow in $ds.Rows) {

    $dataRow ["suid"]

    $dataRow ["status"]

    $dataRow ["accdate"]

    $dataRow ["totcpu"]

    $dataRow ["totio"]

    # for each column you want

    }

    I'm not 100% sure this will work for you since I can't set up a test but I believe it's correct.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply