Use of IronPython in PowerShell

PowerShellからIronPythonを利用する

Use of IronPython in Monad - PowerShell Memoで、MSHからIronPythonを利用するサンプルを紹介しましたが、
当時はIronPythonのバージョンは「1.0 Beta1」でした。
現時点での最新版は「1.0 Beta 7」です。
http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742

Windows PowerShell RC1」+「IronPython 1.0 Beta 7」で試してみる

Windows PowerShell RC1」+「IronPython 1.0 Beta 7」の組み合わせでは、
上記サンプルはエラーが発生し正しく動作しません。

サンプルを実行するとエラーが発生

Exception calling "Execute" with "1" argument(s): "sys.LoadAssemblyByName has b
een deprecated and will be removed in the next release. Please use clr.AddRefer
ence* methods instead."

IronPythonの仕様変更により、「sys.LoadAssemblyByName」メソッドは、次期リリースで削除される予定のようです。
代わりに、「clr.AddReference」メソッドを利用すればよいのですね。


以下のように書き直すと動作します。

[void] [Reflection.Assembly]::LoadFrom("C:\IronPython\IronPython.dll")
$pe = new-object ironpython.hosting.pythonengine

$code=@"
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import *
f = Form(Text="IronPython Sample")
f.ShowDialog()
"@

$pe.Execute($code)