# \[SOVLED\] Crawl a webfolder for a specific file type \[Complete N00b warning\]

**URL:** <https://forums.powershell.org/t/sovled-crawl-a-webfolder-for-a-specific-file-type-complete-n00b-warning/18404>\
**Category:** PowerShell Help\
**Created:** [January 22, 2022, 8:53am UTC](https://forums.powershell.org/t/sovled-crawl-a-webfolder-for-a-specific-file-type-complete-n00b-warning/18404 "2022-01-22T08:53:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgaard](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@jgaard](https://forums.powershell.org/u/jgaard)\
**Post date:** [January 22, 2022, 8:53am UTC](https://forums.powershell.org/t/sovled-crawl-a-webfolder-for-a-specific-file-type-complete-n00b-warning/18404/1 "2022-01-22T08:53:00Z")

</div>

Hi I need a little help. (complete n00b)

I need to get all the CSV files from a homepage (specific folder) and download them to a local folder.

This first part works and I get a nice list of all the \*.CSV files:

```auto
$WebResponse = Invoke-WebRequest "https://somepage.dot/"
$links2 = $WebResponse.links | select href | where {$_.href -like '*csv*'}

```

The next part, not so much I have serveral issues:

1. I need to trim the filename and I know it’s because I’m doing some thing wrong, but I just can not figure out what.

2. Invoke-webrequest also has problems with the trim caracters, so it throws an error: Invoke-WebRequest : Cannot bind parameter ‘Uri’. Cannot convert the “@{href=[https://somepage.dot/somefile.csv](https://somepage.dot/somefile.csv)}” value of type “Selected.System.Management.Automation.PSCustomObject” to type “System.Uri”.

```auto
ForEach ($href in $links2)
{
    $FileName = Split-Path $href -leaf
    $filelocation = "C:\Temp\" + $FileName.Trim("}")
    Invoke-WebRequest $href -OutFile $filelocation
}

```

I know it must be something basic I’m missing.

Kind regards Jgaard.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 22, 2022, 9:08am UTC](https://forums.powershell.org/t/sovled-crawl-a-webfolder-for-a-specific-file-type-complete-n00b-warning/18404/2 "2022-01-22T09:08:38Z")

</div>

jgaard,  
Welcome to the forum. 👋🏽

In PowerShell we work with objects and properties. So there’s barely the need to do string acrobatics like `.Trim()`.

When you output `$links2.href` to the console you will see that there are the plain link paths. So instead of

```auto
ForEach ($href in $links2)

```

you could do

```auto
ForEach ($href in $links2.href)

```

Or inside your loop instead of using only `$href` you use `$href.href`.

---

<div class="post-metadata">

**Author:** ![jgaard](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@jgaard](https://forums.powershell.org/u/jgaard)\
**Post date:** [January 22, 2022, 9:30am UTC](https://forums.powershell.org/t/sovled-crawl-a-webfolder-for-a-specific-file-type-complete-n00b-warning/18404/3 "2022-01-22T09:30:54Z")

</div>

Perfect I knew it was a “small” thing like objects and properties 😉

Thank you for your quick help.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 22, 2022, 9:31am UTC](https://forums.powershell.org/t/sovled-crawl-a-webfolder-for-a-specific-file-type-complete-n00b-warning/18404/4 "2022-01-22T09:31:48Z")

</div>

Great. I’m glad it helped. 👍🏽 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:19pm UTC](https://forums.powershell.org/t/sovled-crawl-a-webfolder-for-a-specific-file-type-complete-n00b-warning/18404/5 "2024-05-16T20:19:41Z")

</div>


