You need to extract the value that was a match. Select-String returns objects, and when you echo what happens $pattern.ToString() . ToString() returns a string, not a match value. This will return only all links:
Get-Content $webpagetxt | Select-String -pattern $regex -Allmatches | % { $_.Matches | % { $_.Value } }
Btw, instead of saving the web page and reopening it with get-content , you can simply split the string into linebreaks to get an array (if that was the only reason you saved it) :-)
$webpage -split "`n" | Select-String -pattern $regex -Allmatches | % { $_.Matches | % { $_.Value } }
EDIT To load it, you can simply extend it with another foreach loop:
$rootDir = "http://website.com/sport/galleries/" $saveDir = "C:\Users\user\Desktop\" $webpage -split "`n" | Select-String -pattern $regex -Allmatches | % { $_.Matches | % { $_.Value } } | % { #Get local path $local = $_.Replace($rootDir, $saveDir) #Create path $file = New-Item $local -ItemType file -Force #Download $wb.DownloadFile($_, $file.FullName) }
source share