Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion - Add proxy support #490

Open
Mrkuff opened this issue Feb 15, 2022 · 4 comments
Open

Suggestion - Add proxy support #490

Mrkuff opened this issue Feb 15, 2022 · 4 comments

Comments

@Mrkuff
Copy link

Mrkuff commented Feb 15, 2022

I was behind a proxy here and I had to change the script to add "-Proxy $Proxy -ProxyCredential $MyCreds" at the end of each "Invoke-WebRequest" cmdlet.

Same thing for "Install-PackageProvider -Name NuGet"

But then, i got error with "Find-DscResource -moduleName $modulename -RequiredVersion $moduleversion | Save-Module -Path "$PSScriptRoot\Temp\DSC"

I've search a long time and try these configuration without success :

Setting TLS 1.2 : [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Bypassing the certificate validation : [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};
Bypassing the certificate validation by code instead of block :
#C# class to create callback
$code = @"
public class SSLHandler
{
public static System.Net.Security.RemoteCertificateValidationCallback GetSSLHandler()
{

    return new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });
}

}
"@
#compile the class
Add-Type -TypeDefinition $code

#disable checks using new class
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [SSLHandler]::GetSSLHandler()

No success!! but then i've found way to configure default proxy but i wasnt able to add it to the script, and I had to install the module outside of the "Prereq" script. here what I use for this to work :

$proxy = 'YER PROXY HERE' # update this
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy($proxy)
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

Install-PackageProvider -Name nuget -Scope AllUsers -Confirm:$false -Force -MinimumVersion 2.8.5.201
Register-PSRepository -Default -verbose

Install-Module -Name xActiveDirectory -Scope AllUsers -Confirm:$false -Force
Install-Module -Name xDHCpServer -Scope AllUsers -Confirm:$false -Force
Install-Module -Name xDNSServer -Scope AllUsers -Confirm:$false -Force
Install-Module -Name NetworkingDSC -Scope AllUsers -Confirm:$false -Force
Install-Module -Name xPSDesiredStateConfiguration -Scope AllUsers -Confirm:$false -Force

Probably there more "code head" people who can help with this since it's ugly but working :)

Thanks again for the great script!

@Mrkuff
Copy link
Author

Mrkuff commented Feb 15, 2022

Oh and .. I've just saw this message for the telemetry :D

Unnecessary files cleanup
Do you want to cleanup unnecessary files and folders?
[Y] Yes [N] No [?] Help (default is "Y"): y
Cleaning unnecessary items
Removing D:\WSLab\Temp
Removing D:\WSLab\1_Prereq.ps1
Removing D:\WSLab\2_CreateParentDisks.ps1
Renaming D:\WSLab\3_Deploy.ps1 to Deploy.ps1
Sending telemetry info
Sending telemetry failed with an error: The remote server returned an error: (407) Proxy Authentication Required.
Transcript stopped, output file is D:\WSLab\CreateParentDisks.log
Job Done. Press enter to continue...

@jaromirk
Copy link
Collaborator

adding @machv :)

@Mrkuff
Copy link
Author

Mrkuff commented Feb 15, 2022

I've rerun the script completely cos i had to change the DC domain name.. and i've just change this from the 1_Prereq.ps1 and it's working now with my proxy :

#set TLS 1.2 for github downloads
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

#set TLS 1.2 and Proxy for github downloads
$proxy = 'YER PROXY HERE' # update this
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy($proxy)
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
Register-PSRepository -Default

@Mrkuff
Copy link
Author

Mrkuff commented Feb 15, 2022

Ok it's the last version of it (without any error message ) :

#set TLS 1.2 and Default Web Proxy for github downloads
$proxy = 'YER PROXY HERE' # update this
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy($proxy)
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants