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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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

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

Virus Depot: Cyber Crime Becomes Big Business

The rising threat of malware-as-a-service is not one to be overlooked. Malware-as-a-service is growing and easily purchased from a full-service cyber-criminal store in a “Virus Depot” fashion. View our webinar recording to learn how to best defend against these attacks!

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

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

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?
BSonPoshCommented:
That is very odd.

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

remove-item $filename -force
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'
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.
jharenAuthor Commented:
So in Task Scheduler I just use powershell.exe with the arguments -command 'C:\PowershellScripts\Mailboxsize\mailboxsize.ps1'
BSonPoshCommented:
yes

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jharenAuthor Commented:
Awesome - thanks for ALL the help -
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.