?
Solved

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

Posted on 2008-11-12
12
Medium Priority
?
6,614 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:jharen
  • 6
  • 6
12 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22941015
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
 

Author Comment

by:jharen
ID: 22941937
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
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22942010
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
 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

 

Author Comment

by:jharen
ID: 22942079
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
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22942161
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
 

Author Comment

by:jharen
ID: 22942232
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
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22942252
That is very odd.

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

remove-item $filename -force
0
 

Author Comment

by:jharen
ID: 22942309
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
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22942334
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
 

Author Comment

by:jharen
ID: 22942457
So in Task Scheduler I just use powershell.exe with the arguments -command 'C:\PowershellScripts\Mailboxsize\mailboxsize.ps1'
0
 
LVL 18

Accepted Solution

by:
BSonPosh earned 2000 total points
ID: 22942489
yes
0
 

Author Closing Comment

by:jharen
ID: 31515986
Awesome - thanks for ALL the help -
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question