Visual Studio "Orcas" June 2007 pre-CTP を BITS でダウンロードするための PowerShell script

こんなこと言われているので,わざわざダウンロードすべきかどうかは微妙なところですが,敢えてダウンロードするよ,という人のためのスクリプト.

The Product Group have release an newer version ov Visual Studio, but they aren't releasing it as a CTP. It is aimed at fixing a couple of problems for some targeted customers. The reality of this isn't tested or upto the quality of a proper CTP. You can still use this download, but it has some problems and it isn't supported for TFS. I would recomend waitining until Beta 2.Sorry for any confussion I have caused.

If you are going to ignore that advice, then you can download the latest pre-CTP from:
http://download.microsoft.com/download/f/2/a/f2ac411f-acf9-42a7-a84f-3efc409bcd6b/VSTS_VPCJuneCTP.mht

以下の手順は Vista でしか試していませんのでご注意ください.まあ別に 2 GB 越えのファイルをダウンロードしようというわけではないので,そこそこのバージョンの BITS (Background Intelligent Transfer Service) と google:bitsadmin.exe がインストールされていれば動くと思います*1.また,いろいろ練習もかねて PowerShell を使っています.
まずはダウンロード用の job を作ります.

bitsadmin /create OrcasJune

次に,ベースイメージをリストに追加.既にダウンロードしているという人は省略して良いでしょう.ダウンロード先はカレントディレクトリにしていますので,好みに応じて適当に調整してください.

bitsadmin /addfile OrcasJune "http://go.microsoft.com/fwlink/?LinkId=94439" ((pwd).Path + "\VSCTPBase.exe")

さていよいよ 7 つの分割ファイルのダウンロードです.ファイル名にある程度規則性があるので,PowerShelltuple (というか record?)連想配列 を利用してパイプライン的に処理してみました.いくつか冗長な行継続記号がありますが,気になる人は適当に省略してください.

(1..7) `
 | ForEach-Object `
{ `
  if($_ -eq 1) `
  { `
     @{'num'=$_; 'ext'=".exe"} `
  } `
  else `
  { `
     @{'num'=$_; 'ext'=".rar"} `
  } `
} `
 | ForEach-Object `
{ `
   @{ `
      'url'="http://go.microsoft.com/fwlink/?LinkId="+[string](94265 + $_.num); `
      'path'=(pwd).Path + "\Jun2007OrcasCTP_VSTS_7PartsTotal.part0" + $_.num + $_.ext `
    } `
} `
 | ForEach-Object `
{ `
   bitsadmin /addfile OrcasJune $_.url $_.path `
}

上からだらだらと読めるのはいいですね.次の処理ブロックにデータを渡すだけのオブジェクトに型名なんて不要ですし,仮の名前 (フィールド名) も接続部分でのみ有効でいてくれればそれで結構です.まあ C# もだんだんこういう方向に進みつつあるような気はしますが.
さてこれで,ファイルリストは完成です.
以下のコマンドでバックグラウンドダウンロードが開始されます.

bitsadmin /resume OrcasJune

モニタリングしたいときはこう.

bitsadmin /monitor

ダウンロードが完了したら以下のように commit します.

bitsadmin /complete OrcasJune

なお,急いでダウンロードしたいという方に BITS は向かないので,別の方法をお探しくださいませ.

*1:ちなみに Vista 標準搭載なのは BITS 3.0.少なくともこのバージョンは 4 GB を超えるようなファイルの HTTP ダウンロードにも対応しています.