Author Posts

May 5, 2017 at 7:14 pm

Learning invoke-webrequest by creating something practical... Script to download all drivers (*.exe) from a dell support page. The script works with-out error. I had a hard time filtering out non exe files and still having a uri to download from. Just looking for feedback. Is there an easier way? How would you do it? I'm self-employed, so I have not access to peer review.
Thanks!!

 $dell = ( (Invoke-WebRequest -Uri http://downloads.dell.com/published/pages/optiplex-740.html#drivers).links | where-Object {$_.href -like "*.exe"})

Foreach ($href in $dell.href){
    $md = (Split-Path -Path $href)
    New-Item -ItemType Directory -path "c:\users\frank\test\$md" -Force
    iwr ("http://downloads.dell.com$href") -outfile "c:\users\frank\test\$href" 
    }
 
# Example of download path:  http://downloads.dell.com/audio/SIGMATEL_STAC-92XX-C-Major-H_A06_R182475.exe

May 6, 2017 at 3:43 pm

I don't know Frank, looks like a pretty clean piece of code to me. As long as it works, I can't, off hand, think of a better way to do it.

May 8, 2017 at 11:37 am

I concur with Curtis. Your code looks pretty compact for what you want to achieve. I'd add some additional error handling (try/catch) and maybe nice verbose/error messages for the consumers of the script/function.

May 8, 2017 at 4:47 pm

Thank you... Thought it seem OK. I have little interaction with other techs period and none that have any desired to use/learn power shell. I greatly appreciate the feedback. I will turn the script into a function, add a little write-verbose, and see if I can make it find the download page by model name. Seem like it would be handy for someone with multiple Dell computers, so I post the final function encase others have a use.