I need to extract data from a csv file if date matches with today’s date.<\/p>\n
Here is a sample CSV file. if the DOB = today’s date, output the entire row.<\/p>\n
name,DOB,email
\nJohn smith, 4/15/2021,j_smith.yahoo.com
\njohn_Doe,4/16/2021,[email protected]<\/p>\n
=======================
\nhere is what I got so far:<\/p>\n
$File = “C:\\report\\users.csv”
\n$Date = Get-Date -Format “MM/dd/yy”
\n$Pattern = “$($date)”
\nGet-Content $File | Select-string -Pattern $Pattern<\/p>\n
I’m not getting any matched result. It will work If I replace the $Pattern with the actual date: Get-Content $File | Select-string -Pattern 4/15/2021.<\/strong> but failed using the variable $Pattern. I also verified the $Pattern output matches the value from the DOB column. (4/15/2021<\/strong>).<\/p>\n any ideas on what I’m doing wrong. struggle with this all night.<\/p>\n Thank you!<\/p>","upvoteCount":3,"answerCount":5,"datePublished":"2021-04-15T05:04:09.000Z","author":{"@type":"Person","name":"spiceuser-xynzs","url":"https://community.spiceworks.com/u/spiceuser-xynzs"},"suggestedAnswer":[{"@type":"Answer","text":" I need to extract data from a csv file if date matches with today’s date.<\/p>\n Here is a sample CSV file. if the DOB = today’s date, output the entire row.<\/p>\n name,DOB,email ======================= $File = “C:\\report\\users.csv” I’m not getting any matched result. It will work If I replace the $Pattern with the actual date: Get-Content $File | Select-string -Pattern 4/15/2021.<\/strong> but failed using the variable $Pattern. I also verified the $Pattern output matches the value from the DOB column. (4/15/2021<\/strong>).<\/p>\n any ideas on what I’m doing wrong. struggle with this all night.<\/p>\n Thank you!<\/p>","upvoteCount":3,"datePublished":"2021-04-15T05:04:09.000Z","url":"https://community.spiceworks.com/t/use-powershell-to-extract-match-date-for-csv-file/796912/1","author":{"@type":"Person","name":"spiceuser-xynzs","url":"https://community.spiceworks.com/u/spiceuser-xynzs"}},{"@type":"Answer","text":" If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n
\nJohn smith, 4/15/2021,j_smith.yahoo.com
\njohn_Doe,4/16/2021,[email protected]<\/p>\n
\nhere is what I got so far:<\/p>\n
\n$Date = Get-Date -Format “MM/dd/yy”
\n$Pattern = “$($date)”
\nGet-Content $File | Select-string -Pattern $Pattern<\/p>\n