This project has moved. For the latest updates, please go here.

Support for Proxies that require authentication

Topics: Feedback
Apr 21, 2013 at 2:20 AM
Edited Apr 21, 2013 at 2:22 AM
Sorry, really should convert this into a propper patch but I'm not ofay with the way CodePlex does patching, so here's a compare from TextPad... I've added two parameters and added a couple of other lines, to add support for proxies that require authentication. I've updated the parameter documentation at the start. Hasn't had a huge ammount of testing, but I can't have gotten it too wrong :)
Compare: (<)C:\TEMP\SPSourceBuilder\AutoSPSourceBuilder.ps1 (58966 bytes)
   with: (>)C:\TEMP\SPSourceBuilder\AutoSPSourceBuilder2.ps1 (61148 bytes)

> .PARAMETER ProxyAuth
>   Specifies whether your proxy requires authentication. If set to $true it will prompt you for credentials.
>   The default value is $false.
> .PAREMETER ProxyAuthType
>   Specifies the authentication method to use with the proxy.
>   Options are: Basic, Digest, NTLM, Negotiate and Passport.
>   The default is NTLM.
<     [Array]$Languages
>     [Array]$Languages,
>   [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()]
>   [Bool]$ProxyAuth = $false,
>   [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()]
>   [String]$ProxyAuthType = "NTLM"
> # Grab credentials if proxy requires them
> If ($ProxyAuth)
> {
>   Write-Host "Please enter the proxy credentials"
>   $ProxyCredentials = Get-Credential
> }
<           $job = Start-BitsTransfer -Asynchronous -Source $url -Destination "$DestinationFolder\$destinationFile" -DisplayName "Downloading `'$file`' to $DestinationFolder\$destinationFile" -Priority Foreground -Description "From $url..." -RetryInterval 60 -RetryTimeout 3600 -ErrorVariable err
>           If (!$ProxyAuth)
>           {
>               $job = Start-BitsTransfer -Asynchronous -Source $url -Destination "$DestinationFolder\$destinationFile" -DisplayName "Downloading `'$file`' to $DestinationFolder\$destinationFile" -Priority Foreground -Description "From $url..." -RetryInterval 60 -RetryTimeout 3600 -ErrorVariable err
>           }
>           Else
>           {
>               $job = Start-BitsTransfer -Asynchronous -Source $url -Destination "$DestinationFolder\$destinationFile" -DisplayName "Downloading `'$file`' to $DestinationFolder\$destinationFile" -Priority Foreground -Description "From $url..." -RetryInterval 60 -RetryTimeout 3600 -ErrorVariable err -ProxyAuthentication $ProxyAuthType -ProxyCredential $ProxyCredentials
>           }
Jun 28, 2013 at 10:33 AM
Edited Jun 28, 2013 at 10:33 AM

I can confirm these changes worked for me.
I also added the following after the param ( ..... ) lines so that it didn't prompt me for each new download
$username = "DOMAIN\USERNAME"
$password = "PASSWORD"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$ProxyCredentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr