header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Searching value in all columns reveived
Last Post 30 Jun 2010 03:31 AM by Bartek Bielawski. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
GACUser is Offline
New Member
New Member
Posts:7
Avatar

--
27 Jun 2010 04:06 AM
    Dear All,

    As a new User, first of all I would like to say Hello! :)
    I have one question - I can't find anywhere how can I search any value in object received. The best way to explain what I mean is show you an example:

    Get-Process | ? {$_.* -like "*VP*"}

    I would like to find all values (not only ProcessNames) "*VP*" in processes running (search it in all columns)

    It is only an example to help me explain what I mean.

    Many thanks for help!
    Kind regards!
    GAC
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    27 Jun 2010 04:50 AM
    (get-process).psobject.properties | where {$_.value -like "*vp*"} | select name,value

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    GACUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    27 Jun 2010 06:38 AM
    Thank you for fast reply! :) Unfortunately it is not exactly what I mean, maybe I explain it not as clear. Ok, one more:
    When I type "Get-process | ft" i see a table with running processes:

    Handles   NPM(K)   PM(K)   WS(K)    VM(M)    CPU(s)    Id     ProcessName
    -------     ------        -----       -----        -----         ------      --      -----------
    52            2               2080      2392        31            0.06     3024    accelerometerST
    106          5               1320     3756         33            0.06     3772    alg
    80            4               2400     5312         45            1.11     2644    BTTray
    62            3               1952     2504         22            0.09     1292    btwdins
    253          7               4548     7376         38            0.45     1948    ccApp
    335          7               4612     3248         46            0.44       952    ccEvtMgr


    I would like to search all of these and find all values for example "52" without column name. Search result result should show me a rows with HANDLES = 52, PM(K) = 1952, Id = 952.

    Is it possible?
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    27 Jun 2010 07:28 AM
    get-process | foreach-object {
    $properties = $_.psobject.properties | where {$_.name -match '^(id|npm|handles)$'}
    $values = $properties | select -ExpandProperty value

    if( ($values -like '*1*').count -eq 3 )
    {
    ($properties | foreach-object { "{0} = {1}" -f $_.name,$_.value }) -join ","
    }

    }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    GACUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    29 Jun 2010 07:51 AM
    Hi. Thank you for reply. I am not sure if you understand me correctly because here: (id|npm|handles) you specify where script may find the value "52". Is it possible to do it without specify?
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    30 Jun 2010 12:28 AM
    Sorry, I'm not following you.

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Bartek BielawskiUser is Offline
    New Member
    New Member
    Posts:43
    Avatar

    --
    30 Jun 2010 03:31 AM
    Funny how small this world is... ;) OP is my work colleague. We had a problem a while ago - how to quickly find AD property with known value but not known name. So question was about that. With Shay's example I managed to get it solved:
    get-qaduser UserWeKnowValueFor -ia | foreach-object {             
        $properties = $_.psobject.properties | Where-Object {             
            $_.value -like 'SomeKnownValue'            
        }            
                    
        if ($properties) {            
            $properties | foreach-object { "{0} = {1}" -f $_.name,$_.value }            
        }            
    }
    Thanks Shay! Greetings Maciej! ;)
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer