More Advanced Functions - Get-Assembly and Get-ExportedType

More Advanced Functions - Get-Assembly and Get-ExportedType

  • Comments 2

Tyson Kopczynski has just published a great article Fun with PowerShell 2.0 Eventing!  That inspired to to write a script to automatically backup my modules directory.  I'm doing a lot of scripting this week and I don't want to lose my work if I make a mistake.  I thought I would write a scripting using PowerShell 2.0 Eventing to watch my directory and then make a backup copy automatically.

The way to do this is with a FileSystem Watcher or something like that.  Here is where the story changes and why the title of this blog is not "Backup Your Modules Automatically with PS V2 Eventing".  I couldn't remember the name of the type to use.  I was about to go code my traditional ad hoc script to find types and thought -1) why aren't I automating this and 2) how many other people would be able to write this.  With that, I decided to formalize my work a bit and share the results.  Attached are Get-Assembly.PS1 and Get-ExportedType.ps1 and a Demo-GetExportedType.txt to walk you through a few examples.

Enjoy!

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Attachment: Get-ExportedType.zip
Leave a Comment
  • Please add 6 and 4 and type the answer here:
  • Post
  • PingBack from http://www.alvinashcraft.com/2008/12/23/dew-drop-december-23-2008/

  • Jeffrey,

    I have been playing with the get-exportedtype.ps1 script and when I run the provided examples I get several errors of the same type:

    Bad argument to operator '-like': Value cannot be null.

    Parameter name: input.

    At C:\Users\jbaratho\Documents\WindowsPowerShell\Scripts\Get-ExportedType.ps1:73 char:70

    +             $Types = $a.GetExportedTypes() | where {$_.BaseType -like <<<<  $BaseType -And $_.Name -like $Name} |sort

    Name

       + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

       + FullyQualifiedErrorId : BadOperatorArgument

    I spent some time debugging the script and it looks like this is caused by types that contain '[' and ']' characters in their name.

    Am I the only one having this error? How can this be fixed?

    Thanks,

    Jacques

Page 1 of 1 (2 items)