Select with object hashtable

Welcome Forums General PowerShell Q&A Select with object hashtable

Viewing 4 reply threads
  • Author
    Posts
    • #207021
      Participant
      Topics: 1
      Replies: 1
      Points: 4
      Rank: Member

      Hello All,

      My script    $vm = get-vm | ft Name, numcpu, memorygb, @{N=”Hard Disk”; E={get-harddisk -VM $_ |
      `select -ExpandProperty CapacityGB }} , @{N=”IP Address”;E={@($_.guest.IPAddress[0])}} -AutoSize

      Give me all vms with hdd sizes of them. But if any vm have more than a few disks results looks like

      {100, 1536, 1224, 1024…}

      What should I change in script to show all  available disk ?

      Is it possible to show disks without brackets { } ?

       

      Regards

      Marek

       

       

       

       

       

    • #207024
      js
      Participant
      Topics: 29
      Replies: 807
      Points: 2,420
      Helping Hand
      Rank: Community Hero

      Put format-table last. It turns everything into format objects for screen text output.

      [pscustomobject]@{name='joe'} | format-table | % gettype 
      
      IsPublic IsSerial Name                                     BaseType
      -------- -------- ----                                     --------
      False    False    FormatStartData                          Microsoft.PowerShell.Commands.Internal.Format.StartData
      False    False    GroupStartData                           Microsoft.PowerShell.Commands.Internal.Format.StartData
      False    False    FormatEntryData                          Microsoft.PowerShell.Commands.Internal.Format.PacketInfoData
      False    False    GroupEndData                             Microsoft.PowerShell.Commands.Internal.Format.ControlInfoData
      False    False    FormatEndData                            Microsoft.PowerShell.Commands.Internal.Format.ControlInfoData
      
      • This reply was modified 2 months, 3 weeks ago by js.
      • This reply was modified 2 months, 3 weeks ago by js.
      • This reply was modified 2 months, 3 weeks ago by js.
      • This reply was modified 2 months, 3 weeks ago by js.
    • #207045
      Participant
      Topics: 1
      Replies: 1
      Points: 4
      Rank: Member

      I don’t understand. Added here

      get-vm | ft Name, numcpu, memorygb, @{N=”Hard Disk”; E={get-harddisk -VM $_ |

      select -ExpandProperty CapacityGB | FT }} , @{N="IP Address";E={@($_.guest.IPAddress[0])}}
      
      but instand of hdd size it shows type "{Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData.."
      I also checked FT in last section
      get-vm | ft Name, numcpu, memorygb, @{N="Hard Disk"; E={get-harddisk -VM $_ |
      

      select -ExpandProperty CapacityGB }} , @{N=”IP Address”;E={@($_.guest.IPAddress[0])}} | FT

      but results is still {100, 1536, 1224, 1024…}

       

    • #207051
      js
      Participant
      Topics: 29
      Replies: 807
      Points: 2,420
      Helping Hand
      Rank: Community Hero

      I don’t understand your code. It’s is convoluted. Please format it with the pre tags and include the output. I don’t have the get-vm command, so I’m also at a disadvantage. Maybe you can turn the array into a string like this.

      (1,2,3) -join ', '
      
      1, 2, 3
      • This reply was modified 2 months, 3 weeks ago by js.
      • This reply was modified 2 months, 3 weeks ago by js.
    • #207063
      Participant
      Topics: 12
      Replies: 516
      Points: 1,182
      Helping Hand
      Rank: Community Hero
      $vm = get-vm | 
          ft Name, numcpu, memorygb, 
              @{N=”Hard Disk”; E={ (get-harddisk -VM $_ |  select -ExpandProperty CapacityGB) -join ',' }} , 
              @{N=”IP Address”;E={ $_.guest.IPAddress[0] }} -AutoSize
      
      • This reply was modified 2 months, 3 weeks ago by Sam Boutros.
Viewing 4 reply threads
  • You must be logged in to reply to this topic.