none
returning a value after doing a search in a text file RRS feed

  • Question

  • i need to be able to take a string, look in a txt file and if a match is found i need to return the contents of what is after the matched word.

    In the example i list below i need to find a match and then return the path (located after the comma


    Contents of text file:
    name,path
    Comp1,\\server\share
    Comp2,\\server\share2
    Comp3,\\server\share3
    Comp4,\\server\share1
    Comp5,\\server\share2

    So for example the input value is Comp5, what i need returned is the path    \\server\share2

    I have the part of searching and finding the value, but i don't know how to have the other part returned.

    I can do this in either Powershell or as a VB script

    Monday, November 16, 2015 8:06 PM

Answers

  • $mappings = import-csv '\\path\to\your\file.csv'
    ($mappings | where-object { $_.Name -eq 'Comp5' } | select Path).Path
    This should do it.
    • Marked as answer by Joekos54 Monday, November 16, 2015 8:29 PM
    Monday, November 16, 2015 8:25 PM

All replies