Home Forums Programming Powershell Query to variable - not wanting table style result RE: Query to variable - not wanting table style result

  • This is the closest I've come to finding a topic on what I'm trying to do. I'm setting a PS variable equal to the results from a query that returns two values per row and there will be multiple rows returned. Here is the PS code:

    $SQL = "SELECT DBName, SFTPFolder FROM db.Export.ExportDBs"

    $Database = SQLCMD -S "server" -U "User" -P "password" -Q $sql

    Using the information above I figured out that $Database[2] would give me my first result row since 0 and 1 were the headers for the result set. I'm trying to use the results in a FOREACH. I'd like to put the DBName in one variable and the SFTPFolder in a different variable within the FOREACH. I tried $Database[2].DBName but it doesn't return the dbname, at least when I'm playing with it from the PS command line. So I'm a bit at a loss. Any help would be most appreciated.