For an explicit proxy account, pass a credential object to -ProxyCredential:

$proxyAccount = Get-Credential
Invoke-WebRequest -Uri https://example.com/ -Proxy http://proxy.example:8080 -ProxyCredential $proxyAccount

Replace the endpoint with the approved service. Get-Credential prompts for an account instead of embedding a password in the command line. This account goes to the intermediary; destination credentials are a separate parameter and cannot answer a proxy's 407.

If the proxy's authentication scheme and process identity support integrated authentication, choose -ProxyUseDefaultCredentials instead. Do not combine it with an explicit proxy credential in the same request.

Check the reference for the PowerShell version running the script. Windows PowerShell and modern PowerShell differ in implementation and parameter availability; supported versions also provide -NoProxy for an explicit direct request.

When the same script behaves differently as a task

Inspect relevant $PSDefaultParameterValues entries and the process's supported proxy configuration. A profile can add command-specific proxy defaults at session startup. A scheduled task can omit that profile and run as a different identity, even though the script file is unchanged.

Compare destination URL, selected endpoint, required proxy method, PowerShell version and explicit versus default credentials, keeping secrets redacted. If proxy authentication succeeds and the destination returns 401, investigate that destination login rather than move the proxy password into the origin credential parameter.

Artihkkalat mat laktásit