Thursday, March 15, 2012

PowerShell for Rapid Prototyping

I do a large amount of work integrating with third party and internal COM and .NET components.  Lately I am doing this just in PS but I still have a heavy need for compiled applications to manage complex production interactive process.

When evaluating or exploring the features of a component I used to do a basic win forms app, add a breakpoint then use a combination of watch variables and the object explorer.  If it comes down to it I may load the assembly into ILSpy by Sharp Code, or the original reflector when it was owned by Lutz.

The variable: psdrive along with Get-Member allow me to explore things very easily.  If you add-type use the passthrou argument and save it to a variable.  This will show you what base classes are made available.

I posted a question on TechNet (http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/494f64ea-7173-44a6-835d-31814d8e3bbf) about pulling out the list of types that can be used from an assembly.


function Get-Type
{
    Param([Regex]$Pattern = '.')
    $ErrorActionPreference = 'SilentlyContinue'
    [AppDomain]::CurrentDomain.GetAssemblies() |
         ForEach-Object { $_.GetExportedTypes() } |
            Where-Object {($_ -match $Pattern) -and $_.IsPublic} |
                Sort-Object FullName
}

#Find All Loaded Soap related Classes
Get-Type '(?i-)soap'

The Regex is case sensitive by default, so the example has a option modifier in the front.



No comments:

Post a Comment