Answered Problem with Format-Custom

  • Saturday, January 19, 2013 5:32 PM
     
     

    Hi,

    Is there a possible way to create a custom table with my own created variables?

    I am working on a script which counts the user objects in different OU's. what I am seeking is piece of code which allow me to have my own predefined variables in a custom table. following script is similar to what I am planning to have:

    $colResults = $objSearcher.FindAll()

    foreach ($objResult in $colResults)
        {$objItem = $objResult.Properties; $objItem.name}

    $countUsers=$colresults.count

    $a = @{Expression={$countusers};Label="Users in Tehrani";width=25}

    $countusers | Format-Table $a


    after launching the script the result is absolutely nothing. the script works well without (| Format-Table $a) though.


    Mahdi Tehrani | Loves Powershell Spreadis Twitter LinkedIn Youtube

All Replies

  • Saturday, January 19, 2013 6:21 PM
     
     

    The code does not make much sense from any perspective.

    The last line is odd.  The pipeline takes objects and passes then to Format-Table.

    This al so ha nothing to do with the Format-Custom CmdLet

    Here is an example of custom properties formatted as a table

    dir c:\windows |Group PSIsContainer|Format-Table Name,@{N='Count';E={$_.Count}} -auto

    Here is your method:

    888 | Format-Table @{N='Count';E={$_.Count}}

    Run both and see what happens 


    ¯\_(ツ)_/¯