question

phantom2000-5377 avatar image
0 Votes"
phantom2000-5377 asked phantom2000-5377 commented

Check whether CSV header is present and read data to an array

Hi,

I have a csv file which has below data.

99096-image.png



I want to compare the headers to a predefined value to check whether the OS exists in the csv file. If it exists, I want to read the data in that column in to an array.

Anybody can help me with how can I achieve this in PowerShell?

Thanks in advance.

windows-server-powershell
image.png (3.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-3213 avatar image
0 Votes"
IanXue-3213 answered phantom2000-5377 commented

Hi,

You could try something like below

 $file = "C:\temp\file.csv"
 $os = "Windows 10"
 $content= Import-Csv -Path $file
 $headers = ($content | Get-Member -MemberType NoteProperty).Name
 if($os -in $headers){
    $kb =  $content.$os
 }

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That does it. Thank you.

0 Votes 0 ·