我正在循环浏览计算机列表并检查磁盘空间。我想将此信息格式化为一个可以添加为电子邮件正文的数组。我希望将整个输出放入一封电子邮件,我知道如何发送每封电子邮件。
这是代码:
$ComputerList = IMPORT-CSV listofcomputers.txt
$tableFragment = ForEach ($Computer in $ComputerList){
$Name = $Computer.Name
$disk = Get-WmiObject Win32_LogicalDisk -ComputerName $Name -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace
$b = ($disk.Size / 1073741824)
$a = ($disk.FreeSpace / 1073741824)
$a = "{0:N1}" -f $a
$b = "{0:N1}" -f $b
if($disk.FreeSpace -lt 10737418240){Write-Host Disk space on $Name is LOW. Only $a GB remaining. -foregroundcolor "magenta"}
else{Write-Host Free disc space on $Name is $a GB, out of $b GB.}
}