Asked by:
Powershell - Downloading file from website

Question
-
Hi Experts,
I am trying to download file from the SharePoint portal.
I was able to login successfully and open the file , but unable to download the file. Could you please advise. Thanks.
$username="username" $password="password" $url = "https://mycompany.com/sites/folder/document.xlsx" $destination = "c:\temp\document.xlsx" $ie = New-Object -ComObject InternetExplorer.Application $ie.Visible = $true $ie.navigate($url) Start-Sleep -Milliseconds 10000 while($ie.Busy){Sleep 1} $ie.Document.getElementByID("Ecom_User_ID").value = $username $ie.Document.getElementByID("Ecom_Password").value = $password Invoke-WebRequest -Uri $url -Outfile $destination $obj = new-object -com WScript.Shell $obj.AppActivate('Internet Explorer') $obj.SendKeys('s') $obj.SendKeys('{Enter}')
- Moved by Bill_Stewart Monday, July 29, 2019 8:08 PM Off-topic
Monday, March 4, 2019 10:28 PM
All replies
-
You cannot use IE to login and then use Invoke to download. You must login with Invoke which is only possible if the site is set up correctly.
\_(ツ)_/
Monday, March 4, 2019 10:58 PM -
Hi JRV,
Is there a way I can use IE to download the file? Thanks
Monday, March 4, 2019 11:32 PM -
I suggest contacting the website to see if they have an API.
\_(ツ)_/
Tuesday, March 5, 2019 12:04 AM -
Check this: https://social.technet.microsoft.com/wiki/contents/articles/39999.sharepoint-20162013online-how-to-download-sharepoint-files-by-powershell-automation.aspx
If you find my reply helpful, please “Mark as Answer” and “Vote”
<sub>Get help on demand > expertise-as-a-service.com</sub>
- Proposed as answer by Nelson Thomas Thursday, March 7, 2019 8:38 AM
Tuesday, March 5, 2019 7:37 AM -
Hi Nelson, I am unable to establish session with this sharepoint site.
Thursday, April 4, 2019 3:53 AM -
Hi JRV,
Can use the below APIs? Sorry for my ignorance as I am still new to this. Thank you
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest
Thursday, April 4, 2019 3:56 AM