1

I'm using the Start-BitsTransfer command to download remote resources in powershell scripts.

However, it seems that the command does not take the correct filename when the url is a short url.

For example, these url: http://ligman.me/1IW1oab redirect actually to http://download.microsoft.com/DOWNLOAD/D/6/7/D670D322-5771-409E-BF34-5B98496DEB0A/MICROSOFT_PRESS_EBOOK_INTRODUCING_AZURE_PDF.PDF (HTTP 301 response).

But when I execute

Start-BitsTransfer http://ligman.me/1IW1oab

The result filename is 1IW1oab

Is there a way to use this command and the obtain the right filename?

Steve B
  • 36,818
  • 21
  • 101
  • 174

2 Answers2

1

Simply using the command no but you can resolve before the shot url in this way:

$url = 'http://ligman.me/1IW1oab'    
$WebClientObject = New-Object System.Net.WebClient
$WebRequest = [System.Net.WebRequest]::create($URL)
$WebResponse = $WebRequest.GetResponse()
$ActualDownloadURL = $WebResponse.ResponseUri.AbsoluteUri
$ObjectProperties = @{ 'Shortened URL' = $URL;
                       'Actual URL' = $ActualDownloadURL}
$ResultsObject = New-Object -TypeName PSObject -Property $ObjectProperties
$WebResponse.Close()
$ResultsObject.'Actual URL'
CB.
  • 58,865
  • 9
  • 159
  • 159
0

The Start-BitsTransfer command includes a -destination switch

Start-BitsTransfer http://ligman.me/1IW1oab -destination AZURE.PDF

In general, for each "url shortening" scenario where using the final URL is the right choice, there's a "redirect for security" scenario that converts a perfectly fine URL into a GUID.

PESMITH_MSFT
  • 350
  • 1
  • 9