Powershell - 电子邮件可用空间信息

s.m*_*hai 3 email windows powershell

我目前正在使用:

$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)
Run Code Online (Sandbox Code Playgroud)

而且我知道使用以下命令我可以找到所有硬盘上的可用空间:

Get-WmiObject WIN32_logicaldisk | sort -desc freespace | select -first 3 | format-table -autosize deviceid,devicetype,providername,freespace,size,volumename;
Run Code Online (Sandbox Code Playgroud)

当我尝试这样做时:

$body = Get-WmiObject WIN32_logicaldisk | sort -desc freespace | select -first 3 | format-table -autosize deviceid,devicetype,providername,freespace,size,volumename;
Run Code Online (Sandbox Code Playgroud)

但我在电子邮件中收到的只是以下内容:

    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
Run Code Online (Sandbox Code Playgroud)

如何使用 powershell 通过电子邮件获得我的可用空间???

Joh*_*nie 5

尝试:

$body = Get-WmiObject WIN32_logicaldisk | sort -desc 自由空间 | 选择 -first 3 | 格式表-autosize deviceid,devicetype,providername,freespace,size,volumename | 串外

我刚刚在我的电脑上试过它,它奏效了。

有关为什么会起作用的一些背景信息,请参阅:

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

JR