The dynamic keyword in C# 4.0 simplifies the interaction with PowerShell variables. C#’s var keyword casts the GetVariable as an object and needs additional code to cajole the object array into a shape that could be worked with.
The embedded PowerShell below creates 4 variables.
- $a – An array of ints piped through a where and foreach
- $b – A hash table
- $c – A simple array
- $d – A string
Printing the string variable results in printing each character.
Next up, using PowerShell’s Add-Member to add a NoteProperty, ScriptProperty and ScriptMethod to a PowerShell object and doing late-bound access in C#. I’ve experimented a bit but no success.
Results
Some References
Using the dynamic keyword is being experimented with other dynamic languages and other ways.



{ 1 comment… read it below or add one }
I think I solved what you were trying to do with C#, PowerShell and the keyword dynamic.
See my post
Running PowerShell from C# with a hint of dynamic.
But I was wandering if may be there was an easier solution like with IronPython.