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

Sara 421 Reputation points
2024-06-14T13:47:45.91+00:00

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 = "https://us-east1.cloud.twistlock.com/us-2-158262581/api/v1/scripts/defender.ps1";
    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 us-east1.cloud.twistlock.com -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