# Align to left

**URL:** <https://forums.powershell.org/t/align-to-left/3436>\
**Category:** PowerShell Help\
**Created:** [November 19, 2014, 3:49am UTC](https://forums.powershell.org/t/align-to-left/3436 "2014-11-19T03:49:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![turbo-mcp](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@turbo-mcp](https://forums.powershell.org/u/turbo-mcp)\
**Post date:** [November 19, 2014, 3:49am UTC](https://forums.powershell.org/t/align-to-left/3436/1 "2014-11-19T03:49:05Z")

</div>

Hi there  
have a quick question  
I have a script that checks for messages send/received on servers  
pretty simple and it works fine.  
I collect all the data to a custom object(server,send,receive)  
then output it like this:  
$data |Ft -autosize  
(I tried other format table kind of views)  
the output I get is like this:

Server Send Receive  
server1 2 5  
server2 10 15

my question is is there away to align the numbers to the left instead of to the right?  
of course it isn’t a big deal I just want to learn new things so im interested to know if  
its something simple  
Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 19, 2014, 4:10am UTC](https://forums.powershell.org/t/align-to-left/3436/2 "2014-11-19T04:10:48Z")

</div>

Yep, you can do that, but I can’t seem to find where this is documented to give you a reference:

```
$properties = @(
    'Server'

    @{ Label = 'Send'; Expression = { $_.Send }; Alignment = 'Left' }
    @{ Label = 'Receive'; Expression = { $_.Receive }; Alignment = 'Left' }
)

$data | Format-Table -Property $properties -AutoSize
```

Most people only use Name (or Label) and Expression when using the hashtable syntax for constructed properties in Format-Table, but you can also set Width and Alignment in there as well.

---

<div class="post-metadata">

**Author:** ![turbo-mcp](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@turbo-mcp](https://forums.powershell.org/u/turbo-mcp)\
**Post date:** [November 19, 2014, 4:24am UTC](https://forums.powershell.org/t/align-to-left/3436/3 "2014-11-19T04:24:46Z")

</div>

amazing stuff:)  
learn something every day and that’s what I like about it  
Thanks again

---

<div class="post-metadata">

**Author:** ![turbo-mcp](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@turbo-mcp](https://forums.powershell.org/u/turbo-mcp)\
**Post date:** [November 19, 2014, 4:33am UTC](https://forums.powershell.org/t/align-to-left/3436/4 "2014-11-19T04:33:27Z")

</div>

only one other small question  
how would this fit into something like this:

# Load psssnapin

if (! (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) )

{Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:Stop}

$starttime=(Get-Date).addhours(-2).ToString()

$endtime=(Get-Date).ToString()

$Data = @()

$servers=Get-TransportServer

# The servers are processed

ForEach ($server in $servers) {

# The commands run on each server.

$Received=($server|invoke-command {get-messagetrackinglog -resultsize unlimited -EventId “receive” -Start $starttime -End $endtime} |?{$\_.ConnectorId -match “Anonymous”} |Measure-Object)

$Sent=($server|invoke-command {get-messagetrackinglog -resultsize unlimited -EventId “send” -Start $starttime -End $endtime} |Measure-Object)

$Data +=New-Object PSObject -Property @{

```
    Server = $server

    ReceivedMessages = $Received.count 

    SentMessages = $Sent.count

        }

```

$Data |FT -AutoSize -Wrap

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 19, 2014, 4:36am UTC](https://forums.powershell.org/t/align-to-left/3436/5 "2014-11-19T04:36:17Z")

</div>

I’m not sure what you want me to be focusing on, there. The only difference I see (as related to the Format-Table command) is the use of the -Wrap switch, and different property names on the input objects (ReceivedMessage and SentMessages, instead of Receive and Send.) The same idea should work; you just need to pass something to the -Property parameter of Format-Table, and the objects passed to that parameter can be hashtables which define the Alignment and/or Width of a column. (Width is pointless if you’re using -AutoSize, but you get the idea.)

---

<div class="post-metadata">

**Author:** ![turbo-mcp](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@turbo-mcp](https://forums.powershell.org/u/turbo-mcp)\
**Post date:** [November 19, 2014, 4:39am UTC](https://forums.powershell.org/t/align-to-left/3436/6 "2014-11-19T04:39:11Z")

</div>

im just not sure if the properties part of the script should go inside the loop(after the custom object)  
or out of the loop

---

<div class="post-metadata">

**Author:** ![turbo-mcp](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@turbo-mcp](https://forums.powershell.org/u/turbo-mcp)\
**Post date:** [November 19, 2014, 4:45am UTC](https://forums.powershell.org/t/align-to-left/3436/7 "2014-11-19T04:45:41Z")

</div>

got it:)  
I just used it at end(out of loop)  
like this:

```
$properties = @(
    'Server'
 
    @{ Label = 'Send'; Expression = { $_.sentmessages
 }; Alignment = 'Left' }
    @{ Label = 'Receive'; Expression = { $_.receivedmessages }; Alignment = 'Left' }
)
 
$data | Format-Table -Property $properties -AutoSize
```

Thanks again  
I check this forum daily and its just amazing stuff and challenges

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 19, 2014, 4:46am UTC](https://forums.powershell.org/t/align-to-left/3436/8 "2014-11-19T04:46:43Z")

</div>

That can go just before the call to Format-Table; no need to put it inside a loop.

BTW, found the documentation I was looking for: [http://technet.microsoft.com/en-us/library/hh849892.aspx](http://technet.microsoft.com/en-us/library/hh849892.aspx) . It just doesn’t show up when you run Get-Help Format-Table -ShowWindow, due to a slight problem with that command (only showing the first paragraph of each property’s description.) If you run Get-Help Format-Table -Full , the documentation does show up in the console. In addition to the Alignment and Width keys, there’s one other that I didn’t mention earlier: FormatString. Example:

```
$data = @(
    [pscustomobject] @{
        Date = Get-Date -Year 2008 -Month 12 -Day 31
    }

    [pscustomobject] @{
        Date = Get-Date -Year 2012 -Month 6 -Day 13
    }
)

Write-Verbose -Verbose 'Default date / time formatting for current culture'
$data | Format-Table -AutoSize | Out-Host

Write-Verbose -Verbose 'Specifying format string ("D" for long date pattern of current culture)'
$properties = @{ Label = 'Date'; Expression = { $_.Date }; FormatString = 'D' }
$data | Format-Table -Property $properties -AutoSize | Out-Host

Write-Verbose -Verbose 'Specifying custom format string'
$properties = @{ Label = 'Date'; Expression = { $_.Date }; FormatString = 'ddd, MMM d yyyy' }
$data | Format-Table -Property $properties -AutoSize | Out-Host
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 19, 2014, 4:51am UTC](https://forums.powershell.org/t/align-to-left/3436/9 "2014-11-19T04:51:23Z")

</div>

Another bit of useful information from that documentation… the Expression can just be a string, if all you’re doing is accessing a property on the input object. No need to write { $\_.Date } when just ‘Date’ will do:

```
$properties = @{ Label = 'Date'; Expression = 'Date'; FormatString = 'ddd, MMM d yyyy' }
```

---

<div class="post-metadata">

**Author:** ![turbo-mcp](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@turbo-mcp](https://forums.powershell.org/u/turbo-mcp)\
**Post date:** [November 19, 2014, 5:31am UTC](https://forums.powershell.org/t/align-to-left/3436/10 "2014-11-19T05:31:53Z")

</div>

Thanks  
very interesting

---

<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:46pm UTC](https://forums.powershell.org/t/align-to-left/3436/11 "2024-05-16T20:46:45Z")

</div>


