Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A GUI-based tool that will search a given directory for all EXE's and DLL's and return file name, description, and version number.
$inputXML = @"
<Window x:Class="FileVersionChecker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FileVersionChecker"
mc:Ignorable="d"
Title="FileVersionChecker" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="115*"/>
<ColumnDefinition Width="373*"/>
<ColumnDefinition Width="29*"/>
</Grid.ColumnDefinitions>
<Image HorizontalAlignment="Left" Height="47" Margin="10,10,0,0" VerticalAlignment="Top" Width="100" Source="\\srv08\UserProfiles\wevertsen\Documents\Visual Studio 2017\Projects\FileVersionChecker\FileVersionChecker\Venetian.png" RenderTransformOrigin="0.493,0.87"/>
<TextBlock Grid.Column="1" HorizontalAlignment="Left" Height="73" Margin="10,10,0,0" TextWrapping="Wrap" Text="Use this tool to return a list of all EXE &amp; DLL file names, descriptions, and version numbers located in a given directory. For assistance with using this tool, please contact LV_IT_SystemsTeam@Sands.com." VerticalAlignment="Top" Width="314"/>
<Button Name="GoButton" Content="Go!" Grid.Column="1" HorizontalAlignment="Left" Margin="288,120,0,0" VerticalAlignment="Top" Width="75" Height="20" RenderTransformOrigin="0.493,2.817"/>
<Label Content="Enter File Path:" Grid.Column="1" HorizontalAlignment="Left" Margin="10,88,0,0" VerticalAlignment="Top"/>
<Label Content="" Grid.Column="1" HorizontalAlignment="Left" Margin="10,114,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.07,0.564" FontStyle="Italic"/>
<TextBox Name="FilePathTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="103,92,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="260"/>
<Label Content="Example: C:\Windows\" Grid.Column="1" HorizontalAlignment="Left" Margin="10,122,0,0" VerticalAlignment="Top" FontStyle="Italic"/>
<ListView Name="ListView" Grid.Column="1" HorizontalAlignment="Left" Height="100" Margin="10,171,0,0" VerticalAlignment="Top" Width="353">
<ListView.View>
<GridView>
<GridViewColumn Header="OriginalFileName" DisplayMemberBinding ="{Binding 'OriginalFileName'}" Width="100"/>
<GridViewColumn Header="FileDescription" DisplayMemberBinding ="{Binding 'FileDescription'}" Width="100"/>
<GridViewColumn Header="FileVersionRaw" DisplayMemberBinding ="{Binding 'FileVersionRaw'}" Width="100"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
"@
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
try {
$Form = [Windows.Markup.XamlReader]::Load( $reader )
}
catch {
Write-Output "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
}
#===========================================================================
# Load XAML Objects In PowerShell
#===========================================================================
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
Function Get-FormVariables {
if ($global:ReadmeDisplay -ne $true) {
Write-Output "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow; $global:ReadmeDisplay = $true
}
Write-Output "Found the following interactable elements from our form" -ForegroundColor Cyan
get-variable WPF*
}
Get-FormVariables
#===========================================================================
# PowerShell Script Section
#===========================================================================
function Get-ProgramVersion {
Param($Path)
$ScriptName = "Get-ProgramVersion";
$GetDateTime = (Get-Date).DateTime;
$FormatDateTime = "{0:MMddyyhhmmss}" -f [datetime]$GetDateTime;
$concatenatedSearchString = $Path + "\*.exe";
$dllSearchString = $Path + "\*.dll";
$searchQuery = (Get-Item $concatenatedSearchString) | Select-Object @{Name = 'OriginalFileName'; expression = {$_.Name}}, @{Name = 'FileDescription'; expression = {$_.VersionInfo.FileDescription}}, @{Name = 'FileVersionRaw'; expression = {$_.FileVersionRaw}}
$searchQueryDll = (Get-Item $dllSearchString) | Select-Object @{Name = 'OriginalFileName'; expression = {$_.Name}}, @{Name = 'FileDescription'; expression = {$_.VersionInfo.FileDescription}}, @{Name = 'FileVersionRaw'; expression = {$_.VersionInfo.FileVersionRaw}}
$searchQuery;
$searchQueryDll;
$searchQuery | Out-File -FilePath c:\temp\$ScriptName$FormatDateTime.txt;
$searchQueryDll | Out-File -FilePath c:\temp\$ScriptName$FormatDateTime.txt -Append;
}
#===========================================================================
# Actually make the objects work
#===========================================================================
$WPFFilePathTextBox.Text = $null;
$fullSearchString = $WPFFilePathTextBox.Text + "*.exe";
$WPFGoButton.Add_Click( {
$WPFlistView.Items.Clear()
start-sleep -Milliseconds 840
Get-ProgramVersion -Path $WPFFilePathTextBox.Text | ForEach-Object {$WPFListView.AddChild($_)}
})
#===========================================================================
# Shows the form
#===========================================================================
Write-Output "To show the form, run the following" -ForegroundColor Cyan '$Form.ShowDialog() | out-null';
$Form.ShowDialog() | out-null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.