Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:31:03+00:00 2026-06-13T05:31:03+00:00

I need your inputs on how to convert the output from a SQL query

  • 0

I need your inputs on how to convert the output from a SQL query into a string in powershell. I am currently doing the following

function ExecuteFromScriptRowset($connectionParams, $file)
{
     return (invoke-sqlcmd @connectionParams 
             -inputFile $file -MaxCharLength 8000000)
}

I use the above function to call a .sql file that does something like

SELECT Names FROM tblXXX

Here is the actual powershell code that I use to invoke the SQL stored proc

$output = ExecuteFromScriptRowset $someDB (Resolve-Path '.\selectXXX.sql')

The output is an array of System.Data.DataRow which I need to convert to a string array. I am currently trying out the following which is not working as intended

$formatOut = @()

for ($i=0; $i -le $output.Length; $i++)
{
    $formatOut = $formatOut + [string]$output[$i]
}

Here is the output of $formatOut is after the for loop and this is not what I was looking for

$formatOut[0] = System.Data.DataRow
$formatOut[1] = System.Data.DataRow
$formatOut[2] = System.Data.DataRow

Could you please let me know what I need to do so that I create a string array of the contents of the $output object

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:31:05+00:00Added an answer on June 13, 2026 at 5:31 am

    What you are seeing is completely normal, because by default ToString will output object type. This is per .NET specifications.

    You can convert a DataRow to array of object using ItemArray, and then join via “,” or whichever join method you prefer, like this:

    $formatOut = $formatOut + ($output[$i].ItemArray -join ",")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert a string of numbers into a string of letters to
need your help in getting user inputs. I want users to type a string
I need your help with display of some comma separated enteries from my database.
I need to convert text file to the String, which, finally, I should put
Output or Input filtering? I constantly see people writing filter you inputs, sanitize your
OK, here's what I want to implement and I need your ideas : Input
Need your help to get the max of CAP_PRICE based on certain criteria in
I need your help in JAVA (with some sample code if possible) regarding to
I need your help. I tried to play an audio file stored in Assets
I need your help with my script. What I'm trying t do is insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.