/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" PowerShell RC2 and Active Directory "," PowerShell : Using IronPython to Connect to AD and... "," PowerShell Session video of Bruce Payette "," PowerShell : Active Directory Part 11 - moving - R... "," PowerShell : Learn about the HashTable Object and ... "," PowerShell : Setting SendAs permission in Exchange... "," PowerShell : Active Directory Part 10 (AD Browser) "," PowerShell "," PowerShell : How Do I randomize a list, and remove... "," PowerShell : Can you do that less cryptic ? "," ")

Friday, September 29, 2006


PowerShell : Hosting IronPython

In last post about using IronPython from PowerShell : Using IronPython to Connect to AD and list children , I did just use the CLI.

In this post I will show how to Use IronPython from Powershell, by hosting it.

I first load the DLL's needed (copy them to PSHOME directory), and then just start using it.



$ipe = new-object IronPython.Hosting.PythonEngine 

$code = @'

import sys
import clr
import System


import System.DirectoryServices

from System.DirectoryServices import *

root = DirectoryEntry()

for c in root.Children: print c.Name

u = root.Children.Find("CN=FooBar")

for p in u.Properties: print p.PropertyName , p.Value

for p in u.Properties.__getitem__("CN"): print p





The results are not lost you can still work with them and you can exchange variables very easy also see examples below :



# You can get back the results by using Evaluate

PS C:\PowerShell> $ipe.Evaluate('root.Children.Find("CN=FooBar")')


# Or you can get the variable

PS C:\PowerShell> $ipe.Globals["u"]


# Set a IronPython Variable

PS C:\PowerShell> $ipe.Globals['domain'] = [adsi]''
PS C:\PowerShell> $ipe.Evaluate('domain.Children.Find("CN=FooBar")')


# and do a Dir (get-member) on that variable in IronPython

PS C:\PowerShell> $ipe.Evaluate('dir(domain)')


As you see its very easy to mix  IronPython and PowerShell parts.

Realy great ! 




Greetings, /\/\o\/\/

Tags : Monad IronPython PowerShell

Blogger Unknown
This doesn't seem to work with PowerShell 1.0 and IronPython 1.0.1. The constructor will result in an exception...
Post a Comment

<< Home


October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?