question

andreasbright-4989 avatar image
0 Votes"
andreasbright-4989 asked IanXue-MSFT edited

Powershell script to upload or email file

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-2016azure-ad-domain-servicesazure-ad-tenant
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SethWH avatar image
1 Vote"
SethWH answered

You should look into using SharePoint Patterns and Practices (PnP):

sharepoint-pnp-cmdlets

Particularly these commands: Connect-PnPOnline and Add-PnPFile



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.