Read a Csv file with powershell and capture corresponding data

后端 未结 3 2116
北恋
北恋 2020-12-03 05:12

Using PowerShell I would like to capture user input, compare the input to data in a comma delimited CSV file and write corresponding data to a variable.

Example:

3条回答
  •  被撕碎了的回忆
    2020-12-03 06:01

    So I figured out what is wrong with this statement:

    Import-Csv H:\Programs\scripts\SomeText.csv |`
    

    (Original)

    Import-Csv H:\Programs\scripts\SomeText.csv -Delimiter "|"
    

    (Proposed, You must use quotations; otherwise, it will not work and ISE will give you an error)

    It requires the -Delimiter "|", in order for the variable to be populated with an array of items. Otherwise, Powershell ISE does not display the list of items.

    I cannot say that I would recommend the | operator, since it is used to pipe cmdlets into one another.

    I still cannot get the if statement to return true and output the values entered via the prompt.

    If anyone else can help, it would be great. I still appreciate the post, it has been very helpful!

提交回复
热议问题