I'm so close, but I can't get some objects appear on a new line

The below is part of a larger script, I played with it to get the formatting right for a section.  Basically, I want to do my results appear like this:

Top ten virtual machines with the more memory that was:

Name, memory

Name, memory

Name, memory

Thank you for helping on this site (many LucD), I was able to return to the notes, and I'm very close to getting the results I want, but it isn't here.

In the part of the script that I realized, my results look like this:

Top ten virtual machines with more memory assigned to them: {}

VMName 12 (GB).

VMname 12 (GB).

VMName 12 (GB).

{VMName 8 (GB)...}

I only changed the actual name of the virtual machine with "VMName", the rest is exactly the appearance of my output.  Thanks for any help, I'm happy I at least could produce the kind of results of sort of the way I wanted.

I tried to join channels and using of the - ExpandProperty of Select, but obviously I got it wrong, but I make progress.

Feature writing-summary {}
$AllVM = get - VM
$TopMemVM = new-Object PSObject
$TopMemVM | Add-Member - MemberType NoteProperty-Name ' Top ten virtual machines with the more memory that was "-value $($AllVM | where {$_.) PowerState - eq "Receptor"} | Sort descending MemoryMB | Select - 10 first name, MemoryMB | {Foreach}
"`n" + $_. Name, [Math]: tour ($_.) (MemoryMB_/1024) + "(GB)"})
Write $TopMemVM. FL
}

Send-MailMessage - SmtpServer ' 12.8.1.6' - to '< m..com >' - and '< [email protected] >' - subjects 'Test' - body (writing-abstract |) Out-String)

The trick to order the pre - V3 properties is with a Select-Object.

Like this

function Write-Summary {
  Get-VM | where { $_.Powerstate -eq 'PoweredOn' } |
  Sort MemoryMB -Descending | Select -First 10 | %{
    New-Object PSObject -Property @{
       Name = $_.Name       MemoryGB = [Math]::round($_.MemoryMB /1024) +'(GB)'    }
  }
}

Send-MailMessage -SmtpServer '12.8.1.6' -From "" -To "" -Subject "Test" `  -body (Write-Summary | Select Name,MemoryGB | Out-String)

Your variation you are actually only to create 1 object, and you place all virtual machines to top 10 in 1 property of this object.

There is no need to use the New-Object.

Something like that

function Write-Summary {
  $AllVM = get-vm  $($AllVM |
      Sort workingset -Descending | Select -First 10 Name, workingset | foreach {
        $_.Name + " " + [string][Math]::round($_.MemoryMB /1024) +'(GB)'      })
}
Send-MailMessage -SmtpServer '12.8.1.6' -From "" -To "" -Subject "Test" `  -body (Write-Summary | Out-String)

Tags: VMware

Similar Questions

Maybe you are looking for