left alignment the output of a powershell command
11,699
Solution 1
Replace your Select-Object with Format-Table like this:
Format-Table -Property @{ Name="Size in GB"; Expression={$_.Sum / 1GB }; Alignment="left"; }
Solution 2
Quick & dirty - format it as a table, auto-sized:
Get-ChildItem c:\users\xxx\desktop -recurse |
Measure-Object -property length -sum|
format-table -autosize @{Name="Total size GB "; Expression={$_.Sum / 1GB}} >> c:\users\xxx\desktop\pwr\bkp.txt
But I prefer to use out-file
instead of redirection:
Get-ChildItem c:\users\xxx\desktop -recurse |
Measure-Object -property length -sum|
format-table @{Name="Total size GB "; Expression={$_.Sum / 1GB}} -autosize |
| out-file -append -path c:\users\xxx\desktop\pwr\bkp.txt
Comments
-
Ciprian almost 2 years
I am running the following command, and I would like to align the output to the left...just can't figure it out:
Basically, this is providing me the size of a specific directory and it is right aligned.
Get-ChildItem c:\users\xxx\desktop -recurse | Measure-Object -property length -sum|Select-object @{Name="Total size GB "; Expression={$_.Sum / 1GB}} >> c:\users\xxx\desktop\pwr\bkp.txt