Wednesday 14 July 2010

Get-AssemblyDetails.ps1

  1. # 
  2. .SYNOPSIS 
  3.     This script demonstrates the Assembly.GetType method. 
  4. .DESCRIPTION 
  5.     This script creates an int32, then calls into .NET to find  
  6.     the assembly that the int32 class comes from. The assembly 
  7.     details are then output. This script is a re-work of an MSDN 
  8.     code sample. 
  9. .NOTES 
  10.     File Name  : Get-AssemblyDetails.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com  
  16.     MSDN Sample posted at: 
  17.         http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getassembly.aspx  
  18. .EXAMPLE 
  19.     PSH [C:\foo]: .\Get-AssemblyDetails.ps1' 
  20.     CodeBase=: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll 
  21. #> 
  22.  
  23. # Set the Type instance to the target class type. 
  24. $Integer1 = New-Object System.Int32 
  25. $Type1 = $Integer1.GetType(); 
  26.  
  27. # Instantiate an Assembly class to the assembly housing the Integer type.   
  28. $SampleAssembly = [System.Reflection.Assembly]::GetAssembly($Integer1.GetType()) 
  29.  
  30. # Gets the location of the assembly using file: protocol. 
  31. "CodeBase=: {0}" -f $SampleAssembly.CodeBase 

No comments: