Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i am currently using:

$emailFrom = "user@host.com"
$emailTo = "destination@host.com"
$subject = "subject"
$body = "message"
$smtpServer = "mail.host.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

and i know that with the folowing command i can find out the free space on all of my hdd:

Get-WmiObject WIN32_logicaldisk | sort -desc freespace | select -first 3 | format-table -autosize deviceid,devicetype,providername,freespace,size,volumename;

when i try to do this:

$body = Get-WmiObject WIN32_logicaldisk | sort -desc freespace | select -first 3 | format-table -autosize deviceid,devicetype,providername,freespace,size,volumename;

but all i get in my email is the folowing:

    Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData 
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData

how can i get my free space via email using powershell???

share|improve this question

4 Answers 4

up vote 5 down vote accepted

Try:

$body = Get-WmiObject WIN32_logicaldisk | sort -desc freespace | select -first 3 | format-table -autosize deviceid,devicetype,providername,freespace,size,volumename | out-string

I've just tried it on my PC and it worked.

For some background on why this works see:

http://blogs.msdn.com/powershell/archive/2006/04/25/how-does-select-string-work-with-pipelines-of-objects.aspx

JR

share|improve this answer
    
+1 - out-string is a good trick; that's going in my bag of tricks. –  user2278 May 29 '09 at 13:38
    
out-string is the answer. You can't really use format-table if you're assigning...it's really meant for output to the console. –  Mike Shepard May 29 '09 at 14:36
    
works like a charm :) –  s.mihai May 29 '09 at 18:41

You could possibly adapt from my post in this thread.

share|improve this answer
    
i will try, but i haven't been able to email the contents of a variable like $body = Get-WmiObject WIN32_logicaldisk i assume there's someting i am missing, but i must mention i have just started using powershell last week –  s.mihai May 29 '09 at 10:07

You can try this:

$body_array = Get-WmiObject WIN32_logicaldisk | sort -desc freespace | select -first 3 | format-table -autosize deviceid,devicetype,providername,freespace,size,volumename;
$body = $body_array.ToString();
share|improve this answer
    
nope. ain't working, all i get in my email now it's System.Object[] –  s.mihai May 29 '09 at 18:38

PowerShell is taking a stream of objects from Get-WMIObject, sorting and selecting a subset, then producing a text rendition of the remaining objects-- not just working with pure text. If you want to get a pure text rendition, you can just change your call to format-table to use select-object instead.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.