# Excessive Width From Get-ChildItem or Out-String or Send-MailMessage

**URL:** <https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177>\
**Category:** PowerShell Help\
**Created:** [November 3, 2020, 6:29am UTC](https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177 "2020-11-03T06:29:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![geelsu](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@geelsu](https://forums.powershell.org/u/geelsu)\
**Post date:** [November 3, 2020, 6:29am UTC](https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177/1 "2020-11-03T06:29:38Z")

</div>

I am not sure which of the cmdlets is producing the excessive width or if any are … perhaps something else is at work here.

I currently am using _Get-ChildItem -Path L:\ | Out-String_ assigned to a variable to capture the contents of a directory.

That variable is used with _-Body_ from the _Send-MailMessage_ cmdlet

But when the output arrives in the e-mail the output is very wide and the columns like MODE, LastWriteTime, and such scrunched together.

Example:

Mode LastWriteTime Length Name

---- ------------- ------ ---- (these don’t line up under the heading)

-a— 10/30/2020 12:31AM RM.0.FTF.DBPART100.2020102513090000009 (then lots of space this way -\>)  
76 (and some lines wrap and have a number which I don’t know what it is)

-a— 10/30/2020 12:32 AM TM.0.FIF.DBPART100.2020102513110000009 (then lots of space this way -\>)  
(and some lines wrap and don’t have this extra number)

&nbsp;

With Out-String I have tried a few parameters like -Width 80 but that does something odd. Using the first example line from above (the RM) file becomes:

-a— 10/30/2020 12:31AM RM.0.FTF.DBPART100.20201025130900000… (then lots of space this way -\>)  
76 **09** (why does the 09 appear on the right instead of left like **09** 76)  
(if I arrow-right to the end of the line, the cursor wraps normally and proceeds to the 76 on the next line)

&nbsp;

Anyway … Can this be formatted better? Or can something produce the output you get with the old _dir.exe_

Kind regards to all

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [November 3, 2020, 6:53am UTC](https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177/2 "2020-11-03T06:53:51Z")

</div>

When formatting for an email, leverage HTML. There is an ebook in the Free Resources that talks about reporting in HTML. The general idea:

```
$files = Get-ChildItem -Path C:\Scripts\*.txt | Select-Object -Property LastWriteTime, FullName

$mailParams = @{
    To = 'user@myemail.com'
    From = 'Pretty Name <do_not_reply@myemail.com>'
    Subject = 'Stuff from Get-ChildItem'
    Body = ($files | ConvertTo-Html -Title 'My Files' | Out-String)
    BodyAsHtml = $true
    SmtpServer = 'smtp.myemail.com'
}

Send-MailMessage @mailParams
```

---

<div class="post-metadata">

**Author:** ![geelsu](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@geelsu](https://forums.powershell.org/u/geelsu)\
**Post date:** [November 3, 2020, 7:17am UTC](https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177/3 "2020-11-03T07:17:16Z")

</div>

Thanks Rob. I will give that a try shortly. Just wanted to report, I figured out what the extra number was. Because of the scrunching the 76 is actually part of the Length i.e. file size which I unfortunately did not include in my examples above. The file size is: 121,396,043,7 **76**

---

<div class="post-metadata">

**Author:** ![geelsu](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@geelsu](https://forums.powershell.org/u/geelsu)\
**Post date:** [November 3, 2020, 8:42am UTC](https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177/4 "2020-11-03T08:42:15Z")

</div>

Thanks Rob, this worked nicely. I will use that source you referenced to see if it has info on making the output sorted by date.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [November 3, 2020, 9:07am UTC](https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177/5 "2020-11-03T09:07:03Z")

</div>

```
$files = Get-ChildItem -Path C:\Scripts\*.txt | 
         Sort-Object -Property LastWriteTime -Descending |
         Select-Object -Property LastWriteTime, FullName
```

---

<div class="post-metadata">

**Author:** ![geelsu](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@geelsu](https://forums.powershell.org/u/geelsu)\
**Post date:** [November 4, 2020, 6:46am UTC](https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177/6 "2020-11-04T06:46:28Z")

</div>

Ok. Show off. 🙂 LOL. But, really, **thank you**.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/excessive-width-from-get-childitem-or-out-string-or-send-mailmessage/15177/7 "2024-05-16T20:29:10Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


