Powershell script to upload or email file

andreas bright 561 Reputation points
2020-11-30T18:33:06.483+00:00

Hi,

We have x number of azure ad registered clients around the world, that we use a 3part remote manaement tool for, we want to publish a script to these machines from this 3part, and that is ok. Today I use a script that download a file from a onedrive for business share using only the following code


$url = "https://xxxxx-my.sharepoint.com/:u:/g/personal/sdsdsdsdsd?download=1"
$output = "c:\HWID\script.ps1"
$start_time = Get-Date

Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"


When I run this I am not prompted to insert any credentials.

What this script does it generate a file I want to upload to the same share. This share is a public share so its possible for everyone to upload, but I am not able to do it with powershell command, it seems I dont have the correct link, and not the right code because it asks for credentials. If I use a webbrowser it does not ask. What code should I use ?

If thats a big code, then how can I for example email that log file instead... ?

All must be done without user interaction.

Thanks for reply.

Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,368 questions
Microsoft Entra
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,382 questions
0 comments No comments
{count} votes

0 additional answers

Sort by: Most helpful