PowerShell output into text file (File Formating Issue)

~OSD~ 2,196 Reputation points
2022-12-30T19:26:54.007+00:00

Hi,

I am using PowerShell to get the information about the Disk Volumes and saving the output into text file.
The saved text file is not well formatted and I am wondering if there is a way to improve the file formatting of the saved file?

Question1 : Possible to improve file formatting of the saved text file?

Question 2: Instead of text file, is it possible to generate a well formatted HTML or PDF file?

Here is what I am doing currently:

275095-image.png

And the saved output is as follows:

275028-image.png

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,718 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
9,898 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,553 questions
{count} votes

Accepted answer
  1. Rich Matheisen 46,811 Reputation points
    2023-01-01T15:52:43.42+00:00

    If you want HTML, it takes a bit more work:

    $props = "DriveLetter", "FriendlyName", "FileSystemType", "DriveType", "HealthStatus", "OperationalStatus", "SizeRemaining", "Size"  
    get-volume |   
        Select-Object $props |  
            ConvertTo-Html |   
                Out-File c:\junk\gv.htm  
    # optional -- if you want to see the web page right away  
    c:\junk\gv.htm  
    

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 46,811 Reputation points
    2022-12-30T19:46:41.073+00:00

    It looks to me as if the problem lies with choice of fonts used to display the text. Try using a font that uses a fixed pitch (i.e., all characters are of the same width).


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.