Download URL content using PowerShell

后端 未结 7 2026
挽巷
挽巷 2020-12-25 15:33

I am working in a script, where I am able to browse the web content or the \'url\' but I am not able to copy the web content in it & download as a file. This is what I h

7条回答
  •  梦谈多话
    2020-12-25 15:44

    As I understand it, you try to use IE because if automatically sends your credentials (or maybe you didn't know of any other option).

    Why the above answers don't work is because you try to download file from SharePoint and you send an unauthenticated request. The response is 401.

    This works:

    PS>$wc=new-object system.net.webclient
    PS>$wc.UseDefaultCredentials = $true
    PS>$wc.downloadfile("your_url","your_file")
    

    if the the current user of Posh has rights to download the file (is the same as the logged one in IE).

    If not, try this:

    PS>$wc=new-object system.net.webclient
    PS>$wc.Credentials = Get-Credential
    PS>$wc.downloadfile("your_url","your_file")
    

提交回复
热议问题