Powershell Script script cannot fit the colums into the display and were removed

I have  a powershell script that gets mailbox sizes, display names, Total Items, and storage limit status and creates a textfile as the output.  

now I get this "WARNING: 2 columns do not fit into the display and were removed." after the file is created.

This script also emails this text file and I am having problems running it with a batch file - it attached the old text file and sends it.
jharenAsked:
Who is Participating?
 
BSonPoshCommented:
yes
0
 
BSonPoshCommented:
You can use the -auto parameter with format-table (ft) and use out-file or out-string with the -width parameter.

The -width will determine how wide the output should be. With out this it is capped at the size of the current window.
0
 
jharenAuthor Commented:
Where would I put that -
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft -autosize DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount,StorageLimitStatus > C:\PowershellScripts\Mailboxsize\mailboxes.txt

Open in new window

0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
BSonPoshCommented:
Try this... if it is still not wide enough. Change the -width 1000 to a higher number (or lower if it is to wide)
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft -autosize DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount,StorageLimitStatus | out-file C:\PowershellScripts\Mailboxsize\mailboxes.txt -width 1000

Open in new window

0
 
jharenAuthor Commented:
That worked Great -

Do you think you can help with my other problem.

I have a script that runs the above script - then emails the results - however its not attaching the "new" file its attaching the old one

then I have a batch file that runs the script:
powershell.exe -command 'C:\PowershellScripts\Mailboxsize\mailboxsize.ps1'


###Send mailbox statistics script
 
###Variables - change these to match what you want
$FromAddress = mailserver
$ToAddress = me
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "mail server"
 
###This gets the mailbox stats
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft -autosize DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount,StorageLimitStatus | out-file C:\PowershellScripts\Mailboxsize\mailboxes.txt -width 1000
 
###This creates the mail message and adds the stats text file as an attachment
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, 
$MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment("C:\PowershellScripts\Mailboxsize\mailboxes.txt")
$SMTPMessage.Attachments.Add($Attachment)
 
###This section sends the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

Open in new window

0
 
BSonPoshCommented:
That is very odd.

You can try to add the date to the filename and see if that helps.

Look at $filename
###Send mailbox statistics script
 
###Variables - change these to match what you want
$FromAddress = mailserver
$ToAddress = me
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "mail server"
$filename = "C:\PowershellScripts\Mailboxsize\mailboxes-$(get-date -f MMddHHssyyyy).txt"
 
###This gets the mailbox stats
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft -autosize DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount,StorageLimitStatus | out-file $filename -width 1000
 
###This creates the mail message and adds the stats text file as an attachment
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, 
$MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment($filename)
$SMTPMessage.Attachments.Add($Attachment)
 
###This section sends the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

Open in new window

0
 
jharenAuthor Commented:
Nope it still grabbed the old one - if I delete the file that there it sends the correct one - so can I add a section to the script that will delete the file after it sends it?
0
 
BSonPoshCommented:
That is very odd.

I am not sure it will help but you can add this at the end

remove-item $filename -force
0
 
jharenAuthor Commented:
okay that looks good - how about my batch file to call the Powershell script - does it look good?

powershell.exe -command 'C:\PowershellScripts\Mailboxsize\mailboxsize.ps1'
0
 
BSonPoshCommented:
that is fine... but you do not need to wrap it in a batch file if you are calling via schedule tasks... you can just use the syntax above.
0
 
jharenAuthor Commented:
So in Task Scheduler I just use powershell.exe with the arguments -command 'C:\PowershellScripts\Mailboxsize\mailboxsize.ps1'
0
 
jharenAuthor Commented:
Awesome - thanks for ALL the help -
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.