Sabtu, 10 Desember 2011

FileVersionInfo Part II

# Powershell v3.0 code
#
Recurses current directory to gather file version information of a boolean property
#
Returns number of Debug,Patched,PreRelease,Private,Special builds
#
Creates csv of those properties in current directory
#
Takes up to three arguments:
#
[mandatory]$filename (e.g. *.dll),$exportflag (e.g. "0" to output csv;default is off), $filetime (default is now)

function Global:Get-fileinfo {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline=$true)]
[object]$filename,
[bool]$exportflag=1,
$filetime=[DateTime]::Now.ToFileTime()
)

$Files=ls -Filter $filename -recurse -File
## $Files=ls -ea 0 -Filter $filename -recurse #remove '-File' to create 2.0 code. Add '-ea 0' as desired.

$FileInfo=$Files |
% {[System.Diagnostics.FileVersionInfo]::GetVersionInfo("$(($_.DirectoryName)+"\"+($_.Name))")}


$Global:DebugBuild=$FileInfo | % {if ($_.IsDebug) {$_}}
$Global:PatchedBuild=$FileInfo | % {if ($_.IsPatched) {$_}}
$Global:PrereleaseBuild=$FileInfo | % {if ($_.IsPreRelease) {$_}}
$Global:PrivateBuild=$FileInfo | % {if ($_.IsPrivateBuild) {$_}}
$Global:SpecialBuild=$FileInfo | % {if ($_.IsSpecialBuild) {$_}}

[hashtable]$Global:Report=@{
"DebugBuild" = '$DebugBuild';
"PatchedBuild" = '$PatchedBuild';
"PrereleaseBuild" = '$PrereleaseBuild';
"PrivateBuild" = '$PrivateBuild';
"SpecialBuild" = '$SpecialBuild' }

if ($exportflag -eq 0)
{
[array]$hasharray=foreach ($i in $Report){$i.Values}
foreach ($i in $hasharray) {invoke-expression $($i.trimEnd("$")) | Export-Csv -ea 0 -Path $filetime$i.csv }
}

write "Total files: $(($Files).count)"
write "Marked Debug: $(($DebugBuild).count)"
write "Marked Patched: $(($PatchedBuild).count)"
write "Marked Prerelease: $(($PrereleaseBuild).count)"
write "Marked Private: $(($PrivateBuild).count)"
write "Marked Special: $(($SpecialBuild).count)"
}

0 komentar:

Posting Komentar