none
Powershell - filter an array RRS feed

  • Question

  • Hi all,

    I am trying to filter an array in power shell for elements which contain a specific pattern.

    I used this command to do so,

    $raw_data | where-object -Property ColumnName -EQ 'Pattern%'

    and I am getting no results, can anyone help? 

    Thanks in advance!

    Mike


    Mike

    Thursday, June 25, 2020 7:58 PM

All replies

  • $raw_data | where-object -Property ColumnName -Like 'Pattern*'

    or

    $raw_data | where-object -Property ColumnName -Match '^Pattern'


    \_(ツ)_/

    Thursday, June 25, 2020 9:25 PM
  • do you know any problems with NOT ?

    I test notmatch, notlike, notcontains but all have problems.

    example

        Import-Module Inventar\xyz.PowerShell.Inventar.dll
        $PCs = Get-InventoryEntry | where {$_.PcName -like "PCA7A"}
        foreach($pc in $pcs){
        if($pc.Anwendungen -notmatch "CORONA"){ 
            $pc.anwendungen 
            " "
            }    
        }

    if -match else works

    Result? Anwendungen (it means software) may be an object and not array? how can i check it?

    Anwendung
    ---------
    WEBGIS   
    OFFICE                                                                                                                          
    CORONA                                                                                                                          
    PUBP/SB_MA5                                                                                                                    

    Name                    MemberType Definition                               
    ----                    ---------- ----------                               
    Equals                  Method     bool Equals(System.Object obj)           
    GetHashCode             Method     int GetHashCode()                        
    GetType                 Method     type GetType()                           
    ToString                Method     string ToString()                        
    Anwendung               Property   string Anwendung {get;set;}              
    Beschreibung            Property   string Beschreibung {get;set;}           
    GruppeImActiveDirectory Property   string GruppeImActiveDirectory {get;set;}


    Chris


    • Edited by -- Chris -- Saturday, July 11, 2020 8:09 AM
    Saturday, July 11, 2020 7:57 AM
  • Please take a look at the examples in the documentation to understand how the different operators work and create a new post if you still have any questions.

    About Comparison Operators

    Saturday, July 11, 2020 8:06 AM