Script to Download and store a Backup

Dear all,
I’m very new on Powershell world. I need your help to set a new script that downloads a backup using an API script and store it to a shared folder. The script must have the credential secured.
Any one can help me?

I was able to use:

Invoke-WebRequest -Uri website -Headers $headers -OutFile $destination

Could you help me with now store it to server folder with secured credetial stored?

Best Regards

@allemontanari Welcome to forums.

Couldn’t see you using credentials in the shared code. Can you give us bit more info about what you are trying to do and if there is any more code please share that as well if possible.

Thank you kvprasoon
I need to create a script to download a file from an URL (API) and store in a server folder

this what I start to create, just the first steps.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$headers = @{

$url = 'Api_Url' 
$destination = 'Server_path'

$copy_result = Invoke-WebRequest -Uri $url -Headers $headers -OutFile $destination -PassThru

if($copy_result.StatusDescription -eq 200)
    ## write to a log that is OK

if ($copy_result.StatusDescription::IsNullOrEmpty($dowload))
	## write to a log that is ERROR