I have a daily task to download the same set of PDF documents from a website and put them on my company SharePoint. Due to IT restrictions the way I have "automated" this using PowerShell is clunky and not ideal as it has to run from my computer, not in the cloud.
The script is below. I cannot maintain an authenticated "web session" in PowerAutomate or extract one-time link to the digital library the files come from.
#Set the log-in parameters
$postParams = @{action='/log-in';username='myusername';password='*******'}
#Log into website at Log-In page and set-up a web session so authentication carries over
Invoke-WebRequest -Uri 'https://www.website/log-in' -Method Post -Body $postParams -SessionVariable NNN
#Extract the one-time digital library link from my-profile page and access the digital library to authenticate the web session
$DigiLibLink = (Invoke-WebRequest -Uri 'https://www.website/my-profile' -WebSession $NNN).Links | Where-Object href -like 'https://digital-libraryURL*' | select -expand href
Invoke-WebRequest -Uri $DigiLibLink -WebSession NNN
#Download the Files using their direct links and the authenticated websession
Invoke-WebRequest 'https://digital-libraryURL/DownloadPDF?nodeid=xxxx' -WebSession $NNN -OutFile 'C:\OneDriveFolder\File1.pdf'
Invoke-WebRequest 'https://digital-libraryURL/DownloadPDF?nodeid=xxxx' -WebSession $NNN -OutFile 'C:\OneDriveFolder\File2.pdf'
Could someone advise how I could achieve these steps, please?
Michael E. Gernaey
566
Super User 2025 Season 1
David_MA
516
Super User 2025 Season 1
stampcoin
492