Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    8

    Unanswered: Powershell help for SQL Resultset

    I need some help ... I find myself somewhat perplexed. Yet this should be easy.
    So I execute a stored procedure from within a powershell function.

    function Stats-Query($SQLServer){
    invoke-sqlcmd -query "EXEC SPROCNAME" -database DATABASENAME -serverinstance $SQLServer
    }

    $Results = Stats-Query $MachineName
    The SPROC is dynamic and will make new column names, based on db names etc. This all works fine and puts results into $Results

    results will be x columns across (unknown name, or quantity).
    results will be ONE row.

    I want to write out
    ColumnName = VALUE from the results

    How can I tweak this part of my code?
    Remember, my results are stored in $Results


    foreach($Column in $Results)
    {
    echo $Column + " = " + $Value
    }

  2. #2
    Join Date
    Sep 2005
    Posts
    8
    If the following helps:

    This is $Results :
    File_one_extract : 45
    File_two_extract : 4
    File_three_extract : 73
    File_four_extract : 39
    File_five_extract : 1


    I want my final output to be:
    File_one.extract = 45
    File_two.extract = 4
    File_three.extract = 73
    File_four.extract = 39
    File_five.extract = 1


    my code so far: but doesn't work
    This should take the column name, reverse it, and replace the first underscore with a period, then reverse it back and set it to $str variable

    then I just want the value

    for this to be done line by line through $results - results will be of unknown name


    foreach($Result in $Results)
    {
    $str = $Result
    $str2 = -join (($str.length-1)..0 | Foreach-Object { $str[$_] })
    $rv=[regex]'_'
    $str2 = $rv.Replace($str2,".",1)
    $str = -join (($str2.length-1)..0 | Foreach-Object { $str2[$_] })
    Write $str + " = "+ $Result.value
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •