February 14, 2012 at 9:53 am
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
February 20, 2012 at 8:21 am
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 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy