Help comparing strings in csv

Welcome Forums General PowerShell Q&A Help comparing strings in csv

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 6 months ago.

  • Author
  • #77043

    Points: 0
    Rank: Member

    I am trying to compare values within a csv. I am taking a csv with device id,description, and location importing the csv then pulling computer description from active directory. I want to compare the 2 descriptions. I am having difficulty with the compare part. The comparison results evaluate to False without exception for both identical and non-identical strings. Can someone please tell me where I am going wrong?

    $LDDes = Import-Csv -Path 'somefilepath'
    $LDDes | Select-Object 'Device Name','Description',@{Name="AD Description";Expression={$_.'Device Name' | get-adcomputer -Properties Description | Select-Object -ExpandProperty Description}},'Computer Location',@{Name='Match';Expression={$_.Description -eq $_.'AD Desription'}}
  • #77061

    Points: 643
    Helping Hand
    Rank: Major Contributor

    you could try it like this:

    $LDDes | ForEach-Object {
        $ADDes = Get-ADComputer -Identity $_.'Device Name' -Properties Description
            'Device Name' = $_.'Device Name'
            'Computer Location' = $_.'Computer Location'
            'Description' = $_.'Description'
            'AD Description' = $ADDes.Description
            'Match' = $_.'Description' -eq $ADDes.Description


  • #77068

    Points: 0
    Rank: Member

    I am on the PowerShell journey myself but here is a suggestion for performance.

    You could pipe to ForEach-Object as Olaf illustrates (which can get the job done) – I do use this when needed. If you're having to process many objects, I would opt for the foreach construct instead.

    When using ForEach-Object, each object is generated from the collection, individually, before entering the pipeline, then processed. Multiply this by hundreds or thousands of objects, and it will take a long time.

    Generate, process. Generate, process. etc.

    When using the foreach construct, all the objects in the collection are generated only once and then processed one at a time. This can be a much faster operation without the overhead of generating individual objects before processing them.

    Generate. Process. Process. Process.

  • #77143

    Points: 0
    Rank: Member

    Thanks guys, much appreciated. This worked perfectly.

The topic ‘Help comparing strings in csv’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort