i am currently using:
$emailFrom = "[email protected]"
$emailTo = "[email protected]"
$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???
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
You can try this:
You could possibly adapt from my post in this thread.
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.