This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Line wrap on output of Powershell Scripts in SA

When I run Powershell ad hoc scripts in SA, I get line wrapping on output lines that exceeds 80 chars.  Has anyone else seen that and/or have a workaround to stop that?  Currently I postprocess the data but I'd like to avoid that.  Thanks!

  • Hello, 

    Which is the version of HPSA that you are using? 

    Is this happening just with the Ad Hoc scripts?


    Luis Sanchez H

    SW Support engineer

  • Version is 10.22 and it happens for both Ad Hoc and Library script.  After about 79 chars of output, it wraps to a new line.

    Example that produces lots of chars on each line:

    ls C:\Windows\System32 -Directory -Recurse | % { $_.FullName }
  • Any solution for this issue? i'm also facing the same problem... After 80th characters output is wrapped into next line... Looking the any solution which we can able to handle by config file or script.... Thanks in advance.

  • This is just a guess, since I cannot recreate the issue in SA 10.51r6.  (I suspect is more of an OS side issue then an SA side.) 

    But, what I suspect your encountering is the default buffer size limitation that is set on the target servers.  Which by default happens to be 80.  I googled a bit and came up with these which you choose would be up to the implementation. 

    Cmdlet:  Out-string or Out-file


    And here is the MS thread I found which lead me to them, in case the discussion helps.

    Hope that helps



  • Hi Rob,

    Thanks for your reply. Already I have tried increasing the width for the powershell console but still its not working in below HPSA Agent version.

    HPSA Agent Ver. - 60.0.71705.4

    Without increasing the width in powershell output is good morethan 80 characters for the below HPSA Agent version

    HPSA Agent Ver. - 60.0.73283.4

    Is there any other solution for the HPSA Agent servers which is having agent version is 60.0.71705.4? Looking the solution without upgrade the HPSA Agent.

    Thanks in advance.

  • Verified Answer

    For the line wrap issue, I found a work around.

    If you use Write-Host as the last element of the pipeline, the output can bypass the 80 char limit.
    Write-Host uses a different rendering mechanism. Out-String will be needed in some scenarios, but
    it alone isn't enough.

    Part of the problem seems to be that the Powershell that HPSA uses does not allow you to change the
    BufferWidth or WindowWidth, causing you to be stuck with 80 char output width.

    Here's a random command that produces wide output. This happens to list the first 10 log files found
    in log folder that have a pathname greater than 80 chars, but it could be any command.

    $SomeCommandWithWideOutput = {
    ls -recurse C:\Windows\system32\winevt\Logs `
    | ? { $_.FullName.length -gt 80 } `
    | select -first 10 `
    | select Mode,LastWriteTime,Length,FullName

    If we're dealing with raw text to output, piping to Write-Host seems to avoid the line wrapping.

    Invoke-Command $SomeCommandWithWideOutput `
    | % { ( $_.Mode,$_.LastWriteTime,$_.Length,$_.FullName ) -join "`t" } `
    | Write-Host

    If we're wanting to use Format-List or Format-Table, Out-String with a fixed width must also be used.
    In these scenarios, you'll just have to guess what the output width will be and make it larger.
    Fortunately, Out-String can handle some really large numbers for -width.

    Format-List Example

    Invoke-Command $SomeCommandWithWideOutput `
    | Format-List `
    | Out-String -width 2048 `
    | Write-Host

    Format-Table Example

    Invoke-Command $SomeCommandWithWideOutput `
    | Format-Table -AutoSize `
    | Out-String -width 2048 `
    | Write-Host

    I consider it a workaround, because if I want to use these scripts in other settings (not just in HPSA),
    I don't want to use Write-Host. Write-Host doesn't allow redirecting output to a file or variable,
    forcing me to write scripts differently when used in HPSA from those used elsewhere.

    Another approach is to pre-process the output (i.e. by Base64 encoding) into a fixed width block of
    data and then decode it on the receiving end.


  • Thanks your solutions is worked fine.