locked
Custom header for table RRS feed

  • Question

  • How do I create header in this case?

    Function memory($ComputerName = ".")
    {

            $memsticks = gwmi -Class win32_physicalmemory -ComputerName $ComputerName
        foreach ($stick in $memsticks)
        {
           
            Write-Host ( $stick.devicelocator,$stick.capacity)
           
        }

    }

     

    Output

     

    DIMM_A 2147483648
    DIMM_B 2147483648

    I want it to be like this

    Slot         Capacity

    DIMM_A 2147483648
    DIMM_B 2147483648

    Monday, October 3, 2011 9:06 AM

Answers

  • Function memory($ComputerName = ".")
    {
    
         gwmi -Class win32_physicalmemory -ComputerName $ComputerName | ft @{n="Slot";e={$_.devicelocator}},Capacity -A
    }
    

    • Marked as answer by herngyih Monday, October 3, 2011 2:59 PM
    Monday, October 3, 2011 2:53 PM

All replies

  • Function memory($ComputerName = ".")
    {
    
         gwmi -Class win32_physicalmemory -ComputerName $ComputerName | select @{n="Slot";e={$_.devicelocator}},Capacity
    }
    


    or for your variant:

    Function memory($ComputerName = ".")
    {
        $memsticks = gwmi -Class win32_physicalmemory -ComputerName $ComputerName
        foreach ($stick in $memsticks) 
        { 
            
           $stick | select @{n="Slot";e={$_.devicelocator}},Capacity
            
        }
    }


    • Edited by Kazun Monday, October 3, 2011 9:13 AM
    • Proposed as answer by Bigteddy Monday, October 3, 2011 9:56 AM
    Monday, October 3, 2011 9:12 AM
  • Can we -autosize the column without duplicate the header?
    Monday, October 3, 2011 2:23 PM
  • Can we -autosize the column without duplicate the header?

    PS >   memory | ft -a
    
    Slot    Capacity
    ----    --------
    DIMM0 2147483648
    DIMM2 2147483648
    

    or change in code:

     select @{n="Slot";e={$_.devicelocator}},Capacity
    
    to 
    
     ft @{n="Slot";e={$_.devicelocator}},Capacity -a
    
    But i prefer first variant.

    Monday, October 3, 2011 2:29 PM
  • The change in code will still have duplicated header.

     

    Slot     Capacity
    ----     --------
    DIMM_A 2147483648



    Slot     Capacity
    ----     --------
    DIMM_B 2147483648

    Monday, October 3, 2011 2:50 PM
  • Function memory($ComputerName = ".")
    {
    
         gwmi -Class win32_physicalmemory -ComputerName $ComputerName | ft @{n="Slot";e={$_.devicelocator}},Capacity -A
    }
    

    • Marked as answer by herngyih Monday, October 3, 2011 2:59 PM
    Monday, October 3, 2011 2:53 PM