D
D
David Fokin2020-12-11 16:35:38
PowerShell
David Fokin, 2020-12-11 16:35:38

How to implement domain authorization in Powershell?

There is a resource at the entrance to which a domain authorization window opens (the standard Windows authorization window), I need to download a file from this resource using PowerShell, having previously authorized it accordingly. tell me how it can be implemented?
Tried like this:

$user = 'login'
$pass = 'password'
$download_url = "https://...."
$local_path = "C:\Temp\monitor.csv"

$secure = $pass | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user, $secure)
$parce = Invoke-WebRequest -Uri $download_url -Credential $cred

$WebClient = New-Object System.Net.WebClient
$WebClient.DonloadFile($download_url, $local_path)


also tried "$secure = Convert-SecureString "password" -AsPlainText -Force"

None of this worked, I get "Unable to connect to remote server" error or 401 error

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
David Fokin, 2020-12-24
@davchik

Thank you all, it turned out to be implemented through default authorization and run the script through the scheduler with the necessary credentials

A
azarij, 2020-12-11
@azarij

there is no Convert-SecureString command. an error should be thrown. try ConvertTo-SecureString.

R
Roman Bezrukov, 2020-12-11
@NortheR73

Try running Invoke-WebRequest -Uri $download_url -Credential(Get-Credential)

W
wisgest, 2020-12-11
@wisgest

Inserting login and password directly into the URL :

$download_url = "https://login:[email protected]/..."

Does not help?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question