How to pass proxy in a PowerShell script for installing defender software

Sara 421 Reputation points

I am getting an error when running a PowerShell script to install defender software on my development server. The error states that "defender.ps1 is not recognized" and that there is an "err: invalid token." I believe this is because the script needs to pass through a proxy to reach the internet. Can someone guide me on how to properly pass the proxy in this script? Additionally, please let me know if there are any syntax errors that I may have missed.

$parameters = @{ 
    Uri = "";
    Method = "Post"; 
    Headers = @{"authorization" = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiYWJyYW5kYW5vQGF0aGVuvyJePoU" }; 
    OutFile = "defender.ps1"; 

if ($PSEdition -eq 'Desktop') { 
    add-type " 
    using System.Net; 
    using System.Security.Cryptography.X509Certificates; 
    public class TrustAllCertsPolicy : ICertificatePolicy{
        public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) {
            return true; 
    [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy; 
} else { 
    $parameters.SkipCertificateCheck = $true; 

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

Invoke-WebRequest @parameters; 
.\defender.ps1 -type dockerWindows -consoleCN -install
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,460 questions
0 comments No comments
{count} votes