Showing posts with label system.reflection.assembly. Show all posts
Showing posts with label system.reflection.assembly. Show all posts

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 

Tuesday, 18 November 2008

Get-AssemblyVersion.ps1

<#
.SYNOPSIS
    Gets the version number for an assembly
.DESCRIPTION
    
.NOTES
    File Name  : Get-AssemblyVersion.ps1
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell V4
.LINK
    http://pshscripts.blogspot.co.uk/2008/07/get-assemblyversionps1.html 
.EXAMPLE
    PSH [C:\foo]: .\Get-AssemblyVersion.ps1'
    Assembly: System.Speech has version number of: 4.0.0.0    
#>

# Start of script

# Define the assembly we want to load - a random reference assembly from SDK 3.0
$Pshfile = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\system.speech.dll"

# Now load the assembly
$Myasm = [System.Reflection.Assembly]::Loadfile($Pshfile)

# Get name, version and display the results
$Aname = $Myasm.GetName()
$Aver =  $Aname.version

# Display results
"Assembly: {0} has version number of: {1}" -f $Aname.name, $aver
# End of script

Monday, 17 November 2008

Get-AssemblyName.ps1


<#
.SYNOPSIS
Gets assembly full name of a loaded assembly
.DESCRIPTION
This script uses reflection to get and assembly, then
gets the assembly's full name
.NOTES
File Name : Get-AssemblyName.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell V2 CTP3
.LINK
http://pshscripts.blogspot.co.uk/2008/11/get-assemblynameps1.html
.EXAMPLE
PSH [C:\foo]: .\Get-AssemblyName.Ps1'
Full name = "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
#>

# Start of script


# Using Reflection to get information from an Assembly:
$o =[System.Reflection.Assembly]::Load("mscorlib.dll")
$name = $o.GetName()


# Display full name
"Full name = `"{0}`"" -f $name
# End of script

Wednesday, 30 July 2008

Get-AssemblyVersion.ps1

<#
.SYNOPSIS
    Gets the version number for an assembly
.DESCRIPTION
    
.NOTES
    File Name  : Get-AssemblyVersion.ps1
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell V2 CTP3
.LINK
    http://pshscripts.blogspot.co.uk/2008/07/get-assemblyversionps1.html
.EXAMPLE
    PSH [C:\foo]: .\Get-AssemblyVersion.ps1'
    Assembly: System.Speech has version number of: 3.0.0.0    
#>

## 
# Start of script
##

# Define the assembly we want to load - a random reference assembly from SDK 3.0
$Pshfile = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\system.speech.dll"

# Now load the assembly
$Myasm = [System.Reflection.Assembly]::Loadfile($Pshfile)

# Get name, version and display the results
$Aname = $Myasm.GetName()
$Aver =  $Aname.version

# Display results
"Assembly: {0} has version number of: {1}" -f $Aname.name, $aver
# End of script