Truncated Output

Welcome Forums General PowerShell Q&A Truncated Output

This topic contains 2 replies, has 2 voices, and was last updated by

11 months, 3 weeks ago.

  • Author
  • #95170

    Points: 50
    Rank: Member

    I have a rather strange issue, when I use the following code to retrieve the PS version from a list of servers, the PS version is truncated. However this doesn't happen all the time, as when I query a short list of servers the output is ok.

    $pcs = Get-ADComputer -Filter "OperatingSystem -like 'Windows 2012 R2 Standard'" -Properties OperatingSystem
    foreach ($computer in $pcs)
           Try {
                 $psver=invoke-command -computername ($ -ScriptBlock {$PSVersionTable.PSVersion.ToString();}
                 $ResultObject = New-Object PSObject -Property @{PSVer = $psver; ComputerName = ($}
                 Write-Host "Error: $($_.Exception.Message)


    ComputerName   PSVer
    TEST01         4.0
    TEST02         4.0
    TEST03         5....

    I did also add $FormatEnumerationLimit = -1, didn;t seem to make any difference.

    Any help much appreciated.

  • #95178

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    That's just the formatting system doing best-guess stuff. I've had it happen to me as well in odd places.

    That's why I ALWAYS write bits bits this as a function. It makes it easier to pipe the function output to Format-Table or Format-List, where I can provide more specific formatting instructions. Remember, **your "main" code shouldn't worry about what the output looks like** . It should just output objects, as you're doing, and let the chips fall where they may. You can then take "external" steps to either explicitly format or, if you're really doing the right thing and building modules, define a custom format view for your output.

    • #95185

      Points: 50
      Rank: Member

      Thanks Don, I've stuck it in a function and can now format it properly, I was thinking script, when I should have been thinking module !

The topic ‘Truncated Output’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort