I am trying to pull out a string of information from a text file using the select-string command in powershell. The text file I am searching is source from an html document. The regex string in other tools seems to pull only the parts I am wanting, however with powershell using the code below I get the entire line below -
href="https://www.test.com/host-details.php?host_id=5252">servername</A>
I would like to exclude everything before the ? so it would only display -
host_id=5252">servername</A>
$input_path = ‘path of text file to search' $output_file = 'output results' $regex = ‘^.*host_id\=([0-9]+)\"\>([^<]+)\<\/A\>.*$’ select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file