0

In order to shift this output table over, I had to create an empty column which puts hyphens where the blank space should be (see picture). I'd like to have the same output as the picture, but without the hyphens, in other words an empty column only.

How can I offset this table, without the need for an empty column?

Current output

How I would like it to appear

My code:

$outputTable = New-Object system.Data.DataTable “$TableName”
#servername     totaldbs    activedbs   passivedbs  preferencecountlist     mounteddbs      dismounteddbs   dagname
$col0 = New-Object system.Data.DataColumn "     ",([string])
$col1 = New-Object system.Data.DataColumn ServerName,([string])
$col2 = New-Object system.Data.DataColumn TotalDbs,([string])
$col3 = New-Object system.Data.DataColumn ActiveDbs,([string])
$col4 = New-Object system.Data.DataColumn PassiveDbs,([string])
$col5 = New-Object system.Data.DataColumn PreferenceCountList,([string])
$col6 = New-Object system.Data.DataColumn MountedDbs,([string])
$col7 = New-Object system.Data.DataColumn DismountedDbs,([string])
$col8 = New-Object system.Data.DataColumn DagName,([string])

$outputTable.columns.add($col0)
$outputTable.columns.add($col1)
$outputTable.columns.add($col2)
$outputTable.columns.add($col3)
$outputTable.columns.add($col4)
$outputTable.columns.add($col5)
$outputTable.columns.add($col6)
$outputTable.columns.add($col7)
$outputTable.columns.add($col8)

foreach($result in $results)
{
    [string]$resultSplit = $result;
    $resultSplit1 = $resultSplit.Split("|"); # -split "|";
    $row = $outputTable.NewRow()

    if ($resultSplit1[6] -ne "")
    {
        $temp6 = $resultSplit1[6];
    }
    else
    {
        $temp6 = "0";
    }

    $temp7 = $resultSplit1[7];

    $row.ServerName = $resultSplit1[0];
    $row.TotalDbs = $resultSplit1[1];
    $row.ActiveDbs = $resultSplit1[2];
    $row.PassiveDbs = $resultSplit1[3];
    $row.PreferenceCountList = $resultSplit1[4];
    $row.MountedDbs = $resultSplit1[5];

    if ($resultSplit1[6] -ne "")
    {
        $row.DismountedDbs = $resultSplit1[6];
    }
    else
    {
        $row.DismountedDbs = "0";
    }

    $row.DagName = $resultSplit1[7];        
    $outputTable.Rows.Add($row);
}

$outputTable | format-table -AutoSize

1 Answer 1

2
($outputTable | format-table -AutoSize | Out-String) -Split '[\r\n]+' | ForEach {"    $_"}

Or using .Replace:

($outputTable | format-table -AutoSize | Out-String) -Replace '[\r\n]+', "`r`n    "
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.