15 responses to “PowerShell 3 – Finally on the DLR!”

  1. Dew Drop – January 5, 2011 (#1,234) | Alvin Ashcraft's Morning Dew

    [...] PowerShell 3 – Finally on the DLR! and Did you know PowerShell can use Selenium? (Joel Bennett) [...]

  2. Paul Cowan

    I wonder if they will fix the stdin bug in powershell3td that leaves powershell hanging sometimes

    http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected

    I find it infuriating.

  3. Henrik Ravn

    “Running a function repeatedly is now MUCH slower than pasting the same code repeatedly into the console”

    Don’t you mean faster?

  4. PowerShell version 3.0 – A Technical Review – Metcorp Consulting Tech Blog

    [...] Powershell 3 – Finally on the DLR! [...]

  5. Episode 172 – vCenter Orchestrator « PowerScripting Podcast

    [...] Joel Bennett posted about the DLR and PowerShell v3 [...]

  6. Josh Einstein

    Unfortunately, it would appear that PowerShell still isn’t able to natively deal with dynamic dispatch objects returned by CLR methods. When I attempt to use an ExpandoObject instance in PowerShell, it just sees the Keys and Values property of it’s underlying IDictionary implementation.

  7. Josh Einstein

    Sure:

    Add-Type -TypeDefinition @"
    using System;
    using System.Collections.Generic;
    using System.Dynamic;
    public static class DynamicMaker {
        public static dynamic MakeDynamic(string propertyName, object value) {
            IDictionary obj = new ExpandoObject();
            obj[propertyName] = value;
            return obj;
        }
    }
    "
    @

    $Obj = [DynamicMaker]::MakeDynamic("Color", [ConsoleColor]::Blue)

    @($Obj) | Format-List
     

    I would expect the result to be:

    Color: Blue

    Instead it is:

    Key: Color
    Value: Blue

    Treating ExpandoObject as a dictionary and not a dynamic object with a single Color property.

  8. Peter Kriegel

    Yeah! I have seen the presentation Video from Jeffrey Snover and Refaat Issa at the Build conference.
    The say execution of code is up to 6* faster.

    As a .NET Developer and Admin, I was crying all the time, about the One-way affair, between PowerShell and the .Net Framework. Because PowerShell takes all advantages of the Framework, but there is no backflow from PowerShell to the Framework (PS-Modules/Snapins as Classes into the Framework, to use it in C# or VB natively).
    I am Happy to go a step forward in this relationship.

    My credo is: PowerShell everywhere! (As a replacement for Kixtart, DOS, VBscript..)
    If you want to use PowerShell for Logon scripts there is a Gap. One of the Arguments against PowerShell for this purpose is that PowerShell starts up to slow. How fast is that with V3 and a script?

    So I see a need for precompiled scripts, to add more speed! What’s with that?

    My next question which comes into mind is; which role plays the .NET Code Access Security in that game?
    (I did not take knowledge of the new .NET 4 CAS)

  9. Josh Einstein

    Ahh thanks, yeah seems like they might want to build in some special case logic for anything imeplementing IDynamicMetaObjectProvider so that it calls the GetDynamicMemberNames method.

    In the meantime I used this as a workaround.

        function ConvertFrom-DictionaryObject {
            process {
                $Obj = New-Object PSObject
                foreach ($Key in $_.Keys) {
                    Add-Member -InputObject $Obj NoteProperty $Key $_[$Key]
                }
                $Obj
            }
        }
     

    But then again doing this is basically the same situation we had in v2.

  10. Josh Einstein

    Okay I have no idea what I am doing with this comment system. :) I meant to reply, and I tried both HTML and Markdown and can’t seem to format my code like you have.