Label Cloud

Monday, August 28, 2006

More Powershell tricks

Two other usefull scriptlets for the powershell

First function filters for only CLR files
Second returns CLR version that the assembly was compiled against.

function IsClr() {
process {
trap {continue;}
$asmb = $null;
$asmb = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($_.FullName);
if ($asmb)
{ $_ }
}
}

function ClrVersion
{
param ([System.IO.FileInfo] $fileInfo)
$asmb = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($fileInfo.FullName);
$refAssemblies = $asmb.GetReferencedAssemblies();
foreach ($refAssembly in $refAssemblies)
{
if ($refAssembly.Name -eq "mscorlib")
{
$refAssembly.Version
break;
}
}
}

Use Examples

dir | Clr

dir | IsClr | foreach-object{$V = ClrVersion($_); $_.Name + " " + $V.ToString()}


Share/Save/Bookmark

No comments: