Reputation: 1203
Very new to the powershell game, thought it was time to skill up into it. I'm doing OK with the operators etc but I'm having trouble actually working with the returned data, I can't seem to wrap my head around it.
I've parsed a file using Get-Content and a Select-String and passed the returned line into a variable $temp1.
If I look at the properties of $test1 using:
>>$temp1 | select-object -expandproperty Matches
I get the following output:
Groups : {http://download.avgfree.com/softw/13free/update/u13iavi5825cq.bin, 5825cq}
Success : True
Captures : {http://download.avgfree.com/softw/13free/update/u13iavi5825cq.bin}
Index : 447
Length : 65
Value : http://download.avgfree.com/softw/13free/update/u13iavi5825cq.bin
The line itself is a long string of garbage, what I'm actually after is now contained in the Value property but for the life of me I can't figure out how to actually USE it!
Basically what I want to do is use the address in the Value property to issue a download of that particular file.
Apologies if I'm not clear, today is my first PS day so I'm still struggling even to get around the jargon!
Thanks in advance.
Upvotes: 1
Views: 5229
Reputation: 201602
On PowerShell V1/2 try:
$temp1 | Foreach {$_.Matches} | Foreach {$_.Value}
V3 has a nifty member enumeration feature that allows you to simplify that to:
$temp1.Matches.Value
$temp1
can contain more than one matched line and each matched line could contain more than one match (eg if you used the -AllMatches
parameter on Select-String
). So it is necessary to iterate all the Matches and for each match, access its Value property.
Upvotes: 4