Trying to learn how to use Powershell to help with pulling data from various sources and banging my head on a poorly formed CSV. I have a CSV that just has a text string in the first cell of each row. Each row has a hash of a file, some data and the hash of the program that wrote it. I need to extract the first hash after "link hash=" below to another file.
[enter code here][1]
If the image doesn't work the first lines read:
The file "<share><link hash="randomhash1">C:\random\location\file.exe</link></share>" was first detected on a local disk. The file was created by the application "<share><link hash="differenthash">C:\windows\explorer.exe</link></share>".
The file "<share><link hash="randomhash2">C:\random\location\file.exe</link></share>" was first detected on a local disk. The file was created by the application "<share><link hash="differenthash">C:\windows\explorer.exe</link></share>".
The file "<share><link hash="randomhash3">C:\random\location\file.exe</link></share>" was first detected on a local disk. The file was created by the application "<share><link hash="differenthash">C:\windows\explorer.exe</link></share>".
The file "<share><link hash="randomhash4">C:\random\location\file.exe</link></share>" was first detected on a local disk. The file was created by the application "<share><link hash="differenthash">C:\windows\explorer.exe</link></share>".
I have been looking for a way to tell powershell to give me the value for "hash=" "" in a new CSV, but hitting syntax errors and obviously just doing it tremendously wrong. As I am trying to learn this, if somebody could state this is the regex and why I would be eternally grateful.
Below is what I have tried. Looking at Select-String I have a knowledge gap on how to get the regex match to become an object I can output. If I take out the ForEach-Object argument I get a csv with a true statement for each line.
Import-Csv C:\Users\me\Desktop\Bad_hash.csv | Select-string -Pattern "(?\w+)" | ForEach-Object {$hash = $_.Matches[0].Groups['hash'].Value [PSCustomObject] @{ Hash = $hash}} | | Export-Csv C:\Users\me\Desktop\test.csv