Archives
-
PowerShell: script to show detailed information on a set of assemblies
To get some insight in your assemblies you can use the script below. It gets all information out that I required, but you can extend it if you need for example all assemblies an assembly depends on.
One thing that was new for we was that I needed functions in a script that can be executed in a pipeline. You can define these functions in the begin {} block.
Save the following code as Get-AssemblyInformation.ps1. Call for example as follows:
get-childitem -path "D:\MyProject\tools" -filter '*.dll' -recurse | D:\bin\Get-AssemblyInformation.ps1
Or if all files are in a folder:
Get-AssemblyInformation.ps1 –Path "D:\MyProject\tools"
Get-AssemblyInformation.s1- #requires -version 2.0
- [CmdletBinding(DefaultParameterSetName="Path")]
- param(
- [Parameter(Mandatory=$true,
- Position=0,
- ParameterSetName="Path",
- ValueFromPipeline=$true,
- ValueFromPipelineByPropertyName=$true)]
- [ValidateNotNullOrEmpty()]
- [string[]]
- $Path,
- [Alias("PSPath")]
- [Parameter(Mandatory=$true,
- Position=0,
- ParameterSetName="LiteralPath",
- ValueFromPipelineByPropertyName=$true)]
- [ValidateNotNullOrEmpty()]
- [string[]]
- $LiteralPath
- )
- Begin
- {
- Set-StrictMode -Version 2.0
- function Get-AssemblyCustomProperty
- {
- param
- (
- $assembly,
- $TypeNameLike,
- $Property = $null
- )
- $value = $null
- foreach ($attribute in $assembly.GetCustomAttributes($false))
- {
- if ($attribute.GetType().ToString() -like "*$TypeNameLike*")
- {
- if ($Property -ne $null)
- {
- # Select-Object -ExpandProperty fails if property value is $null
- try {
- $value = $attribute | Select-Object -ExpandProperty $Property
- }
- catch {
- $value = $null
- }
- }
- else
- {
- $value = $attribute
- }
- break;
- }
- }
- $value
- }
- function Get-AssemblyInfoAsHashtable
- {
- param
- (
- [System.Reflection.Assembly]$assembly
- )
- $info = @{}
- $info.FullName = $assembly.FullName
- $info.Name = $assembly.ManifestModule.Name
- $info.Location = $assembly.Location
- $info.ImageRuntimeVersion = $assembly.ImageRuntimeVersion
- $info.GlobalAssemblyCache = $assembly.GlobalAssemblyCache
- $info.Title = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'Title' -Property 'Title'
- $info.Configuration = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'Configuration' -Property 'Configuration'
- $info.Description = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'Description' -Property 'Description'
- $info.Company = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'Company' -Property 'Company'
- $info.Product = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'Product' -Property 'Product'
- $info.Copyright = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'Copyright' -Property 'Copyright'
- $info.Trademark = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'Trademark' -Property 'Trademark'
- $info.DelaySign = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'DelaySign' -Property 'DelaySign'
- $info.KeyName = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'KeyName' -Property 'KeyName'
- $info.ClsCompliant = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'ClsCompliant' -Property 'IsCompliant'
- $info.ComVisible = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'ComVisible' -Property 'Value'
- $info.IsJITTrackingEnabled = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'System.Diagnostics.DebuggableAttribute' -Property 'IsJITTrackingEnabled'
- $info.IsJITOptimizerDisabled = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'System.Diagnostics.DebuggableAttribute' -Property 'IsJITOptimizerDisabled'
- $info.DebuggingFlags = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'System.Diagnostics.DebuggableAttribute' -Property 'DebuggingFlags'
- $info.CompilationRelaxations = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'CompilationRelaxations' -Property 'CompilationRelaxations'
- $info.WrapNonExceptionThrows = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'System.Runtime.CompilerServices.RuntimeCompatibilityAttribute' -Property 'WrapNonExceptionThrows'
- $info
- }
- function Get-AssemblyInformation
- {
- param
- (
- $AssemblyFile
- )
- try
- {
- $assembly = [Reflection.Assembly]::LoadFile($AssemblyFile)
- $info = Get-AssemblyInfoAsHashtable -assembly $assembly
- $info.IsValidDotNetAssembly = $true
- }
- catch { # it is not a valid dotnet assembly
- $info = @{
- FullName = $AssemblyFile;
- Name = Split-Path -Path $AssemblyFile -Leaf;
- IsValidDotNetAssembly = $false
- }
- }
- $info
- }
- }
- Process
- {
- if ($psCmdlet.ParameterSetName -eq "Path")
- {
- # In the non-literal case we may need to resolve a wildcarded path
- $resolvedPaths = @()
- foreach ($apath in $Path)
- {
- $resolvedPaths += @(Resolve-Path $apath | Foreach { $_.Path })
- }
- }
- else
- {
- $resolvedPaths = $LiteralPath
- }
- foreach ($rpath in $resolvedPaths)
- {
- $PathIntrinsics = $ExecutionContext.SessionState.Path
- if ($PathIntrinsics.IsProviderQualified($rpath))
- {
- $rpath = $PathIntrinsics.GetUnresolvedProviderPathFromPSPath($rpath)
- }
- $assemblyInfo = Get-AssemblyInformation -AssemblyFile $rpath
- Write-Host "***************************************************************************************************"
- Write-Host "**************** $($assemblyInfo.Name)"
- Write-Host "***************************************************************************************************"
- $assemblyInfo
- Write-Host ""
- }
- }
Thanks goes to Keith Hill for some of the more advances parameter stuff which is lent from http://rkeithhill.wordpress.com/2009/01/28/tail-content-%E2%80%93-better-performance-for-grabbing-last-lines-from-large-ascii-log-files/.
-
PowerShell: PrimalForms and the TFS source control provider
I’m using PrimalForms 2011 for designing PowerShell front-ends and editing some PowerShell. Code is under source control (TFS), and PrimalForms has a Source Control tab. Initially the “Providers” section was empty, after installing Team Foundation Server MSSCCI Provider 2010 and restarting PrimalForms I got my provider:
If you open a file under TFS source control you can now right-click on the file to do our source control operations: