diff --git a/Public/OSDCloud/Edit-OSDCloud.winpe.ps1 b/Public/OSDCloud/Edit-OSDCloud.winpe.ps1 index 603d54d5..463afdb2 100644 --- a/Public/OSDCloud/Edit-OSDCloud.winpe.ps1 +++ b/Public/OSDCloud/Edit-OSDCloud.winpe.ps1 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 #======================================================================= diff --git a/Public/WebConnection.ps1 b/Public/WebConnection.ps1 index c09ca856..72826088 100644 --- a/Public/WebConnection.ps1 +++ b/Public/WebConnection.ps1 @@ -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 { @@ -68,4 +88,4 @@ function Wait-WebConnection { } until ((Test-WebConnection -Uri 'powershellgallery.com') -eq $true) } $Error.Clear() -} \ No newline at end of file +} diff --git a/Public/WebFile.ps1 b/Public/WebFile.ps1 index 1d3c77c6..2a3a3e3e 100644 --- a/Public/WebFile.ps1 +++ b/Public/WebFile.ps1 @@ -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 @@ -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 { @@ -91,4 +120,4 @@ function Save-WebFile { } #======================================================================= } -} \ No newline at end of file +}