Skip to content

Added Experimental Proxy Support to Edit-OSDCloud.winpe.ps1 #13

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions Public/OSDCloud/Edit-OSDCloud.winpe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ function Edit-OSDCloud.winpe {
[string[]]$PSModuleInstall,

[string]$WebPSScript,
[string]$Wallpaper
[string]$Wallpaper,
[string]$Proxy = $null,
[ValidateSet('NTLM','Basic','Negotiate')]
[string]$ProxyType = "Basic",
[string]$ProxyUser = $null,
[string]$ProxyPassword = $null
)
#=======================================================================
# Start the Clock
Expand Down Expand Up @@ -123,8 +128,8 @@ function Edit-OSDCloud.winpe {
foreach ($Driver in $CloudDriver) {
if ($Driver -eq 'Dell'){
Write-Verbose "Adding $Driver CloudDriver"
if (Test-WebConnection -Uri 'http://downloads.dell.com/FOLDER07062618M/1/WINPE10.0-DRIVERS-A23-PR4K0.CAB') {
$SaveWebFile = Save-WebFile -SourceUrl 'http://downloads.dell.com/FOLDER07062618M/1/WINPE10.0-DRIVERS-A23-PR4K0.CAB'
if (Test-WebConnection -Uri 'http://downloads.dell.com/FOLDER07062618M/1/WINPE10.0-DRIVERS-A23-PR4K0.CAB' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType) {
$SaveWebFile = Save-WebFile -SourceUrl 'http://downloads.dell.com/FOLDER07062618M/1/WINPE10.0-DRIVERS-A23-PR4K0.CAB' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType
if (Test-Path $SaveWebFile.FullName) {
$DriverCab = Get-Item -Path $SaveWebFile.FullName
$ExpandPath = Join-Path $DriverCab.Directory $DriverCab.BaseName
Expand All @@ -139,8 +144,8 @@ function Edit-OSDCloud.winpe {
}
if ($Driver -eq 'HP'){
Write-Verbose "Adding $Driver CloudDriver"
if (Test-WebConnection -Uri 'https://ftp.hp.com/pub/softpaq/sp110001-110500/sp110326.exe') {
$SaveWebFile = Save-WebFile -SourceUrl 'https://ftp.hp.com/pub/softpaq/sp110001-110500/sp110326.exe'
if (Test-WebConnection -Uri 'https://ftp.hp.com/pub/softpaq/sp110001-110500/sp110326.exe' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType) {
$SaveWebFile = Save-WebFile -SourceUrl 'https://ftp.hp.com/pub/softpaq/sp110001-110500/sp110326.exe' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType
if (Test-Path $SaveWebFile.FullName) {
$DriverCab = Get-Item -Path $SaveWebFile.FullName
$ExpandPath = Join-Path $DriverCab.Directory $DriverCab.BaseName
Expand All @@ -153,11 +158,11 @@ function Edit-OSDCloud.winpe {
}
if ($Driver -eq 'WiFi'){
Write-Verbose "Adding $Driver CloudDriver"
if (Test-WebConnection -Uri 'https://downloadmirror.intel.com/30280/a08/WiFi_22.40.0_Driver64_Win10.zip') {
if (Test-WebConnection -Uri 'https://downloadmirror.intel.com/30280/a08/WiFi_22.40.0_Driver64_Win10.zip' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType) {
#$WiFiDownloads = (Invoke-WebRequest -Uri 'https://downloadmirror.intel.com/30280/a08/WiFi_22.40.0_Driver64_Win10.zip' -UseBasicParsing).Links
#$WiFiDownloads = $WiFiDownloads | Where-Object {$_.download -match 'Driver64_Win10.zip'} | Sort-Object Download -Unique | Select-Object Download, Title -First 1
#$SaveWebFile = Save-WebFile -SourceUrl $WiFiDownloads.download
$SaveWebFile = Save-WebFile -SourceUrl 'https://downloadmirror.intel.com/30280/a08/WiFi_22.40.0_Driver64_Win10.zip'
$SaveWebFile = Save-WebFile -SourceUrl 'https://downloadmirror.intel.com/30280/a08/WiFi_22.40.0_Driver64_Win10.zip' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType
if (Test-Path $SaveWebFile.FullName) {
$DriverCab = Get-Item -Path $SaveWebFile.FullName
$ExpandPath = Join-Path $DriverCab.Directory $DriverCab.BaseName
Expand All @@ -173,8 +178,8 @@ function Edit-OSDCloud.winpe {
}
if ($Driver -eq 'Nutanix'){
Write-Verbose "Adding $Driver CloudDriver"
if (Test-WebConnection -Uri 'https://github.com/OSDeploy/OSDCloud/raw/main/Drivers/WinPE/Nutanix.cab') {
$SaveWebFile = Save-WebFile -SourceUrl 'https://github.com/OSDeploy/OSDCloud/raw/main/Drivers/WinPE/Nutanix.cab'
if (Test-WebConnection -Uri 'https://github.com/OSDeploy/OSDCloud/raw/main/Drivers/WinPE/Nutanix.cab' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType) {
$SaveWebFile = Save-WebFile -SourceUrl 'https://github.com/OSDeploy/OSDCloud/raw/main/Drivers/WinPE/Nutanix.cab' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType
if (Test-Path $SaveWebFile.FullName) {
$DriverCab = Get-Item -Path $SaveWebFile.FullName
$ExpandPath = Join-Path $DriverCab.Directory $DriverCab.BaseName
Expand All @@ -189,8 +194,8 @@ function Edit-OSDCloud.winpe {
}
if ($Driver -eq 'VMware'){
Write-Verbose "Adding $Driver CloudDriver"
if (Test-WebConnection -Uri 'https://github.com/OSDeploy/OSDCloud/raw/main/Drivers/WinPE/VMware.cab') {
$SaveWebFile = Save-WebFile -SourceUrl 'https://github.com/OSDeploy/OSDCloud/raw/main/Drivers/WinPE/VMware.cab'
if (Test-WebConnection -Uri 'https://github.com/OSDeploy/OSDCloud/raw/main/Drivers/WinPE/VMware.cab' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType) {
$SaveWebFile = Save-WebFile -SourceUrl 'https://github.com/OSDeploy/OSDCloud/raw/main/Drivers/WinPE/VMware.cab' -proxy $proxy -ProxyUser $proxyUser -ProxyPassword $ProxyPassword -ProxyType $ProxyType
if (Test-Path $SaveWebFile.FullName) {
$DriverCab = Get-Item -Path $SaveWebFile.FullName
$ExpandPath = Join-Path $DriverCab.Directory $DriverCab.BaseName
Expand Down Expand Up @@ -270,10 +275,14 @@ start PowerShell -Nol -W Mi
}
}
Write-Verbose -Verbose "Saving $Module to $MountPath\Program Files\WindowsPowerShell\Modules"
Save-Module -Name $Module -Path "$MountPath\Program Files\WindowsPowerShell\Modules" -Force
$secpasswd = ConvertTo-SecureString -String $ProxyPassword -AsPlainText -Force
[pscredential]$ProxyCredential = New-Object System.Management.Automation.PSCredential("$ProxyUser" , $secpasswd)
Save-Module -Name $Module -Path "$MountPath\Program Files\WindowsPowerShell\Modules" -Force -proxy $proxy -ProxyCredential $ProxyCredential
}
Write-Verbose "Saving OSD to $MountPath\Program Files\WindowsPowerShell\Modules"
Save-Module -Name OSD -Path "$MountPath\Program Files\WindowsPowerShell\Modules" -Force
$secpasswd = ConvertTo-SecureString -String $ProxyPassword -AsPlainText -Force
[pscredential]$ProxyCredential = New-Object System.Management.Automation.PSCredential("$ProxyUser" , $secpasswd)
Save-Module -Name OSD -Path "$MountPath\Program Files\WindowsPowerShell\Modules" -Force -proxy $proxy -ProxyCredential $ProxyCredential
#=======================================================================
# PSModuleCopy
#=======================================================================
Expand Down
28 changes: 24 additions & 4 deletions Public/WebConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,45 @@ function Test-WebConnection {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline = $True)]
[string]$Uri = 'google.com'
[string]$Uri = 'https://google.com',
[string]$Proxy ,
[ValidateSet('NTLM', 'Basic', 'Negotiate')]
[string]$ProxyType = "Basic",
[string]$ProxyUser = $null,
[string]$ProxyPassword = $null
)

begin {}

process {
$Params = @{
Method = 'Head'
Uri = $Uri
Method = 'Head'
Uri = $Uri
UseBasicParsing = $True
}

try {
if ($proxy -ne "") {
if (($ProxyUser -ne "") -and ($ProxyPassword -ne "")) {
Write-Verbose "Add Proxy: Proxy: $proxy with User $ProxyUser"
$secpasswd = ConvertTo-SecureString -String $ProxyPassword -AsPlainText -Force
[pscredential]$ProxyCredential = New-Object System.Management.Automation.PSCredential("$ProxyUser" , $secpasswd)
$Params.Add("Proxy", "$proxy")
$Params.Add("ProxyCredential", $ProxyCredential)
}
else {

Write-Verbose "Add Proxy: $proxy without Credentials"
$Params.Add("Proxy", "$proxy")
}
}
Write-Verbose "Test-WebConnection OK: $Uri"
Invoke-WebRequest @Params | Out-Null
$true
}
catch {
Write-Verbose "Test-WebConnection FAIL: $Uri"
$Error[0]
$false
}
finally {
Expand Down Expand Up @@ -68,4 +88,4 @@ function Wait-WebConnection {
} until ((Test-WebConnection -Uri 'powershellgallery.com') -eq $true)
}
$Error.Clear()
}
}
37 changes: 33 additions & 4 deletions Public/WebFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ function Save-WebFile {

#Overwrite the file if it exists already
#The default action is to skip the download
[switch]$Overwrite
[switch]$Overwrite,
[string]$Proxy = $null ,
[ValidateSet('NTLM', 'Basic', 'Negotiate')]
[string]$ProxyType = "Basic",
[string]$ProxyUser = $null,
[string]$ProxyPassword = $null
)
#=======================================================================
# DestinationDirectory
Expand Down Expand Up @@ -65,13 +70,37 @@ function Save-WebFile {
#=======================================================================
if (Get-Command 'curl.exe') {
Write-Verbose "cURL: $SourceUrl"
$curlopt = ""
if($Proxy -ne $null){
$curlopt += " --proxy $proxy"
if($ProxyType){
if ($ProxyType -eq "Basic") {
$curlopt += " --proxy-basic"
}
elseif ($ProxyType -eq "NTLM") {
$curlopt += " --proxy-ntlm"
}
elseif ($ProxyType -eq "Negotiate") {
$curlopt += " --proxy-negotiate"
}
}
if($ProxyUser -ne $null -and $ProxyPassword -ne $null){
$curlopt += " --proxy-user $proxyUser`:$proxyPassword"
}elseif($ProxyUser -ne $null){
$curlopt += " --proxy-user $proxyUser"
}
}

if ($host.name -match 'ConsoleHost') {
Invoke-Expression "& curl.exe --location --output `"$DestinationFullName`" --url `"$SourceUrl`""

Write-Host "& curl.exe --location --output `"$DestinationFullName`" --url $SourceUrl $curlopt"
Invoke-Expression "& curl.exe --location --output `"$DestinationFullName`" --url $SourceUrl $curlopt"
}
else {
#PowerShell ISE will display a NativeCommandError, so progress will not be displayed
$Quiet = Invoke-Expression "& curl.exe --location --output `"$DestinationFullName`" --url `"$SourceUrl`" 2>&1"
Write-Verbose "& curl.exe --location --output `"$DestinationFullName`" --url $SourceUrl $curlopt 2>&1"
$Quiet = Invoke-Expression "& curl.exe --location --output `"$DestinationFullName`" --url $SourceUrl $curlopt 2>&1"
$Quiet
}
}
else {
Expand All @@ -91,4 +120,4 @@ function Save-WebFile {
}
#=======================================================================
}
}
}