Invoke-WebRequest Feedback

This topic contains 3 replies, has 3 voices, and was last updated by  Frank Tucker 5 months, 1 week ago.

  • Author
    Posts
  • #70243

    Frank Tucker
    Participant

    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
    
  • #70267

    Curtis Smith
    Participant

    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.

  • #70285

    Daniel Krebs
    Moderator

    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.

  • #70307

    Frank Tucker
    Participant

    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.

You must be logged in to reply to this topic.