Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting date into mailbox table? 1

Status
Not open for further replies.

kokser

Programmer
Sep 25, 2009
90
DK
Thought I'd make a new thread about this.

My current script exports mailbox information to a csv file, but I want to add the date to the table.

Script (without export part):
Code:
get-mailbox | get-mailboxstatistics | where {$_.ObjectClass -eq "Mailbox"} | Select-Object @{name="Username";expression={$_.DisplayName}},@{name="Size";expression={$_.TotalItemSize.Value.ToKB()}}, @{name="Items";expression={$_.ItemCount}}, @{name="DN";expression={(get-mailbox $_.legacydn).distinguishedname}}
I haven't polished the script yet, but this works so far.

I have tried addin different lines, but I can't quite figure out how to do this.

Obviously adding a get-date doesn't work at either end of this script, as the current date is no where to be found in the mailbox.

Code:
get-date -format d | get-mailbox | get-mailboxstatistics
Code:
| get-date @{name="Dato";expression={(get-date)}}
Neither works at any end of the script :/

Any help appreciated, as always! :)
 
Select-Object actually creates a new object, so you aren't limited to just pulling existing properties from the preceding object. You can add other calculated fields as part of the Select-Object statement. Practically, that means you can do this:
Code:
$date = get-date -format d

[...getmailboxes...] | Select-Object @{name="Username";expression={$_.DisplayName}},@{name="Size";expression={$_.TotalItemSize.Value.ToKB()}}, @{name="Items";expression={$_.ItemCount}}, @{name="DN";expression={(get-mailbox $_.legacydn).distinguishedname}}, @{name="Date";expression={$date}}
 
Interesting, I get the todays-date for each user, which is great, exactly what I wanted :) Unfortunately, the output is not a table anymore :S It formats it to lines, and I can't figure out where to put the |ft to get a table. Maybe there's another way to do it?
 
I were a bit too fast there, Just figured it out :p

Code:
get-mailbox | get-mailboxstatistics | where {$_.ObjectClass -eq "Mailbox"} | Select-Object @{name="Username";expression={$_.DisplayName}},@{name="Size";expression={$_.TotalItemSize.Value.ToKB()}}, @{name="Items";expression={$_.ItemCount}}, @{name="DN";expression={(get-mailbox $_.legacydn).distinguishedname}}, @{name="Dato";expression={$date}} |ft
Works perfect, thanks a lot! :)
 
Again I were too quick on the trigger. Maybe I should make a new thread for this problem, but I'll just start here.

My complete script:
Code:
$date = get-date -format d
$file = $date+".csv"
$output = get-mailbox | get-mailboxstatistics | where {$_.ObjectClass -eq "Mailbox"} | Select-Object @{name="Username";expression={$_.DisplayName}},@{name="Size";expression={$_.TotalItemSize.Value.ToKB()}}, @{name="Items";expression={$_.ItemCount}}, @{name="DN";expression={(get-mailbox $_.legacydn).distinguishedname}}, @{name="Dato";expression={$date}} |ft
$output | export-csv -path $file -encoding ascii -notypeinformation
Until I added the date and formatted the table, the output was fine, but now I just get this weird output (as seen so many times, when something is wrong)
Code:
#TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
ClassId2e4f51ef21dd47e99d3c952918aff9cd,pageHeaderEntry,pageFooterEntry,autosizeInfo,shapeInfo,groupingEntry
033ecb2bc07a4d43b5ef94ed5a35d280,,,,Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo,
9e210fe47d09416682b841769c78b8a3,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
27c87ef9bbda4f709f6b4002fa4af63c,,,,,
4ec4f0187cb04f4cb6973460dfe252df,,,,,
cf522b78d86c486691226b40aa69e95c,,,,,
I suspect the |ft at the end to do this, but I need the output to be a table (I think?) when I export it to a csv file.
 
Surprisingly (to me), removing |ft worked, and it's in a perfect table in the export :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top