Support for Proxies that require authentication

Topics: Feedback
Apr 21, 2013 at 3:20 AM
Edited Apr 21, 2013 at 3: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)

36a36,42
> .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.
60c67,71
<     [Array]$Languages
---
>     [Array]$Languages,
>   [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()]
>   [Bool]$ProxyAuth = $false,
>   [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()]
>   [String]$ProxyAuthType = "NTLM"
77a88,93
> # Grab credentials if proxy requires them
> If ($ProxyAuth)
> {
>   Write-Host "Please enter the proxy credentials"
>   $ProxyCredentials = Get-Credential
> }
122c139,147
<           $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 11:33 AM
Edited Jun 28, 2013 at 11:33 AM
Hello,

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
Thanks!