-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetFileHashInformation.ps1
More file actions
630 lines (544 loc) · 21.5 KB
/
GetFileHashInformation.ps1
File metadata and controls
630 lines (544 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
<#
.SYNOPSIS
This script provides a graphical user interface (GUI) for viewing and copying File Hash Information of files.
.DESCRIPTION
The script creates a WPF-based GUI that allows users to drag and drop files to view their File Hash Information.
The script supports MD5, SHA1, and SHA256 hash algorithms.
It also provides functionality to copy these properties to the clipboard and to clear the displayed information.
Additionally, the script includes options to install and uninstall a context menu item for files to retrieve their properties.
.PARAMETER FilePath
Optional parameter to specify the path of the file to automatically load the information for.
.NOTES
Author: Michael Escamilla
Date: 10-13-2024
Version History:
2024-10.13.0- Initial release of the GetFileHashInformation.ps1 script.
#>
param (
[Parameter(Mandatory = $false)]
[string]$FilePath
)
#############################################
################# Variables #################
#############################################
# Script Name
$Global:ScriptName = "GetFileHashInformation.ps1"
# Script Version
[System.Version]$Global:ScriptVersion = "2024.10.13.0"
# Right-Click Menu Name
$Global:RightClickMenuName = "Get File Hash Information"
# Get the Security Principal
$Global:currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
#############################################
################# Functions #################
#############################################
#region Functions
function Test-FileLock {
param (
[Parameter(Mandatory = $true)]
[string]$Path
)
try {
$FileStream = [System.IO.File]::Open("$($Path)", 'Open', 'Write')
$FileStream.Close()
$FileStream.Dispose()
return $false
}
catch {
return $true
}
}
function Enable-AllButtons {
# Get all button variables
$Buttons = Get-Variable -Name "btn_*" -ValueOnly -ErrorAction SilentlyContinue
foreach ($Button in $Buttons) {
# Enable Button
$Button.IsEnabled = $true
}
}
function Disable-AllButtons {
# Get all button variables
$Buttons = Get-Variable -Name "btn_*" -ValueOnly -ErrorAction SilentlyContinue
foreach ($Button in $Buttons) {
# Disable Button
$Button.IsEnabled = $false
}
}
function Clear-Textboxes {
# Get all textbox variables
$Textboxes = Get-Variable -Name "txt_*" -ValueOnly -ErrorAction SilentlyContinue
foreach ($Textbox in $Textboxes) {
# Disable Button
$Textbox.Clear()
}
}
# Stolen from: https://github.com/PatchMyPCTeam/CustomerTroubleshooting/blob/Release/PowerShell/Get-LocalContentHashes.ps1
Function Get-EncodedHash {
[CmdletBinding()]
Param(
[Parameter(Position = 0)]
[System.Object]$HashValue
)
$hashBytes = $hashValue.Hash -split '(?<=\G..)(?=.)' | ForEach-Object { [byte]::Parse($_, 'HexNumber') }
Return [Convert]::ToBase64String($hashBytes)
}
function Get-FileHashInformation {
param (
[Parameter(Mandatory = $true)]
[IO.FileInfo[]]$Path
)
Write-Host "Getting File Hash Information for: [$Path]"
# Initialize the hash object
$Hashes = @{}
# Get File Hash - MD5
$FileHashMD5 = Get-FileHash -Path $Path -Algorithm MD5
$Hashes["MD5"] = $FileHashMD5
# Get File Hash - SHA1
$FileHashSHA1 = Get-FileHash -Path $Path -Algorithm SHA1
$Hashes["SHA1"] = $FileHashSHA1
# Get File Hash - SHA256
$FileHashSHA256 = Get-FileHash -Path $Path -Algorithm SHA256
$Hashes["SHA256"] = $FileHashSHA256
# Get File Hash - SHA1 - Encoded
$FileHashEncoded = Get-EncodedHash -HashValue $FileHashSHA1
$Hashes["Digest"] = $FileHashEncoded
# Return the hash object
$Hashes
}
function Set-TextboxInformation {
param (
[Parameter(Mandatory = $true)]
[hashtable]$FileHashInfo
)
# Set the File Hash Information textboxes
$txt_MD5.Text = $FileHashInfo.MD5.Hash
$txt_SHA1.Text = $FileHashInfo.SHA1.Hash
$txt_SHA256.Text = $FileHashInfo.SHA256.Hash
$txt_Digest.Text = $FileHashInfo.Digest
}
#endregion Functions
#############################################
################# Main Script ################
#############################################
# Load Assemblies
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
# Build the GUI
[xml]$XAMLformFileHashProperties = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="form1"
Width="900"
Height="250"
ResizeMode="NoResize"
Title="Get File Hash Information"
FontSize="12">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="Right Click Menu">
<MenuItem Name="MenuItem_Install"
Header="Install"/>
<MenuItem Name="MenuItem_Uninstall"
Header="Uninstall"/>
</MenuItem>
<MenuItem Header="About">
<MenuItem Name="MenuItem_GitHub"
Header="GitHub - GetFileHashInformation"/>
<MenuItem Name="MenuItem_About"
Header="michaeltheadmin.com"/>
<Separator/>
<MenuItem Name="MenuItem_Version"
Header="Version 1.0.0"
IsEnabled="False"/>
</MenuItem>
</Menu>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="0.15*"/>
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="Label">
<Setter Property="Margin"
Value="2.5"/>
<Setter Property="HorizontalAlignment"
Value="Stretch"/>
<Setter Property="HorizontalContentAlignment"
Value="Right"/>
<Setter Property="VerticalAlignment"
Value="Stretch"/>
<Setter Property="VerticalContentAlignment"
Value="Center"/>
<Setter Property="IsEnabled"
Value="True"/>
</Style>
<Style TargetType="TextBox">
<Setter Property="Margin"
Value="2.5"/>
<Setter Property="Width"
Value="Auto"/>
<Setter Property="HorizontalAlignment"
Value="Stretch"/>
<Setter Property="VerticalAlignment"
Value="Stretch"/>
<Setter Property="VerticalContentAlignment"
Value="Center"/>
<Setter Property="IsEnabled"
Value="True"/>
<Setter Property="IsReadOnly"
Value="True"/>
</Style>
<Style TargetType="Button">
<Setter Property="Margin"
Value="2.5"/>
<Setter Property="Width"
Value="Auto"/>
<Setter Property="HorizontalAlignment"
Value="Stretch"/>
<Setter Property="VerticalAlignment"
Value="Stretch"/>
<Setter Property="VerticalContentAlignment"
Value="Center"/>
<Setter Property="IsEnabled"
Value="False"/>
</Style>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalAlignment"
Value="Stretch"/>
<Setter Property="HorizontalContentAlignment"
Value="Center"/>
<Setter Property="VerticalAlignment"
Value="Stretch"/>
<Setter Property="VerticalContentAlignment"
Value="Center"/>
<Setter Property="Height"
Value="{Binding ElementName=lsbox_FilePath, Path=ActualHeight}"/>
</Style>
</Grid.Resources>
<!-- Row 0 -->
<!-- MD5 -->
<Label
Grid.Row="0"
Grid.Column="0"
Name="lbl_MD5"
Content="MD5"/>
<TextBox
Grid.Row="0"
Grid.Column="1"
Name="txt_MD5"
xml:space="preserve"/>
<Button
Grid.Row="0"
Grid.Column="2"
Name="btn_MD5_Copy"
Content="Copy"/>
<!-- Row 1 -->
<!-- Row SHA1 -->
<Label
Grid.Row="1"
Grid.Column="0"
Name="lbl_SHA1"
Content="SHA1"/>
<TextBox
Grid.Row="1"
Grid.Column="1"
Name="txt_SHA1"
xml:space="preserve"/>
<Button
Grid.Row="1"
Grid.Column="2"
Name="btn_SHA1_Copy"
Content="Copy"/>
<!-- Row 2 -->
<!-- Row SHA256 -->
<Label
Grid.Row="2"
Grid.Column="0"
Name="lbl_SHA256"
Content="SHA256"/>
<TextBox
Grid.Row="2"
Grid.Column="1"
Name="txt_SHA256"
xml:space="preserve"/>
<Button
Grid.Row="2"
Grid.Column="2"
Name="btn_SHA256_Copy"
Content="Copy"/>
<!-- Row 3 -->
<!-- Digest -->
<Label
Grid.Row="3"
Grid.Column="0"
Name="lbl_Digest"
Content="Digest"/>
<TextBox
Grid.Row="3"
Grid.Column="1"
Name="txt_Digest"
xml:space="preserve"/>
<Button
Grid.Row="3"
Grid.Column="2"
Name="btn_Digest_Copy"
Content="Copy"/>
<!-- Row -->
<ListBox
Grid.Row="10"
Grid.Column="1"
Name="lsbox_FilePath"
Margin="5"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
AllowDrop="True"
IsEnabled="True"
TabIndex="0">
<ListBox.Items>
<ListBoxItem>
<TextBlock Text="Drag and drop files here"/>
</ListBoxItem>
</ListBox.Items>
</ListBox>
<Button
Grid.Row="10"
Grid.Column="3"
Name="btn_FilePath_Copy"
Content="Copy"/>
</Grid>
</DockPanel>
</Window>
"@
# Create a new XML node reader for reading the XAML content
$readerformFileHashProperties = New-Object System.Xml.XmlNodeReader $XAMLformFileHashProperties
# Load the XAML content into a WPF window object using the XAML reader
[System.Windows.Window]$formFileHashProperties = [Windows.Markup.XamlReader]::Load($readerformFileHashProperties)
# Create Variables for all the controls in the XAML form
$XAMLformFileHashProperties.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name ($_.Name) -Value $formFileHashProperties.FindName($_.Name) -Scope Global }
#############################################
############## Event Handlers ###############
#############################################
#region Event Handlers
#### Form Load #####
$formFileHashProperties.Add_Loaded({
# Check if the script is running as an administrator
if (($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
Write-Warning "The script is running as an administrator."
Write-Warning "Drag and Drog will not work while running as an administrator."
# Clear the listbox
$lsbox_FilePath.Items.Clear()
# Add a warning message to the listbox
$lsbox_FilePath.Items.Add("WARNING: Running as Administrator | Drag and Drop will not work.")
# Make the warning message bold and yellow
$lsbox_FilePath.Background = [System.Windows.Media.Brushes]::Yellow
$lsbox_FilePath.FontWeight = 'Bold'
}
# Update Version Information
$formFileHashProperties.Title = "Get File Hash Information - Version $($ScriptVersion)"
$MenuItem_Version.Header = "Version $($ScriptVersion)"
# Check if the FilePath parameter is provided to script
if ($FilePath) {
# Check if $FilePath is locked
if (Test-FileLock -Path $FilePath) {
Write-Warning "The file is locked: [$FilePath]"
# Clear the listbox
$lsbox_FilePath.Items.Clear()
# Add an error message to the listbox
$lsbox_FilePath.Items.Add("ERROR: The file is locked:`n[$FilePath]")
# Make the Error message bold, red and yellow
$lsbox_FilePath.Background = [System.Windows.Media.Brushes]::Red
$lsbox_FilePath.Foreground = [System.Windows.Media.Brushes]::Yellow
$lsbox_FilePath.FontWeight = 'Bold'
$lsbox_FilePath.FontSize = 16
}
else {
# Get the File Hash Information
$HashInfo = Get-FileHashInformation -Path $FilePath
# Populate the textboxes
Set-TextboxInformation -FileHashInfo $HashInfo
# Enable the Copy buttons
Enable-AllButtons
# Clear the listbox and add the filename
$lsbox_FilePath.Items.Clear()
$lsbox_FilePath.Items.Add($FilePath)
}
}
})
#### Listbox Drag and Drop ####
$lsbox_FilePath.Add_Drop({
$filename = $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)
if ($filename) {
# Check if $FilePath is locked
if (Test-FileLock -Path "$($filename)") {
Write-Warning "The file is locked: [$filename]"
# Clear the listbox
$lsbox_FilePath.Items.Clear()
# Add an error message to the listbox
$lsbox_FilePath.Items.Add("ERROR: The file is locked:`n[$filename]")
# Make the Error message bold, red and yellow
$lsbox_FilePath.Background = [System.Windows.Media.Brushes]::Red
$lsbox_FilePath.Foreground = [System.Windows.Media.Brushes]::Yellow
$lsbox_FilePath.FontWeight = 'Bold'
$lsbox_FilePath.FontSize = 16
}
else {
# Get the File Hash Information
$HashInfo = Get-FileHashInformation -Path $filename
# Populate the textboxes
Set-TextboxInformation -FileHashInfo $HashInfo
# Enable the Copy buttons
Enable-AllButtons
# Clear the listbox
$lsbox_FilePath.Items.Clear()
# Reset the listbox font style
$lsbox_FilePath.ClearValue([System.Windows.Controls.Control]::BackgroundProperty)
$lsbox_FilePath.ClearValue([System.Windows.Controls.Control]::ForegroundProperty)
$lsbox_FilePath.ClearValue([System.Windows.Controls.Control]::FontWeightProperty)
$lsbox_FilePath.ClearValue([System.Windows.Controls.Control]::FontSizeProperty)
# Add the filename to the listbox
$lsbox_FilePath.Items.Add($filename[0])
}
}
})
$lsbox_FilePath.Add_DragOver({
# Check if the dragged data contains file drop data
if ($_.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop)) {
foreach ($File in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) {
# Set the drag effect to Copy
$_.Effects = [System.Windows.DragDropEffects]::Copy
}
}
})
#### Menu Items ####
$MenuItem_Install.add_Click({
Write-Host "Menu Item Install Clicked"
# Set Script Name
$SaveAsScriptName = $ScriptName
# Create a new directory in the LOCALAPPDATA folder
Write-Host "Creating $([System.IO.Path]::GetFileNameWithoutExtension($ScriptName)) folder in LOCALAPPDATA folder"
$DestinationFolderPath = "$env:LOCALAPPDATA\$([System.IO.Path]::GetFileNameWithoutExtension($ScriptName))"
if (-not (Test-Path $DestinationFolderPath)) {
$DestinationFolder = New-Item -ItemType Directory -Path $DestinationFolderPath -ErrorAction SilentlyContinue
}
else {
$DestinationFolder = Get-Item -Path $DestinationFolderPath
}
# Check if the script is being Invoked from the Internet
if ($PSCommandPath -ne "") {
# Copy the script to the new directory
Write-Host "Copying Script to $([System.IO.Path]::GetFileNameWithoutExtension($ScriptName)) Folder"
Copy-Item "$PSScriptRoot\$([System.IO.Path]::GetFileName($PSCommandPath))" -Destination "$($DestinationFolder.FullName)\$($SaveAsScriptName)" -ErrorAction SilentlyContinue
}
else {
Write-Host "PSCommandPath is not available."
# Script URL
$ScriptURL = "https://raw.githubusercontent.com/MichaelEscamilla/GetFileHashInformation/main/GetFileHashInformation.ps1"
Write-Host "Downloading the script from URL: [$ScriptURL]"
try {
Invoke-WebRequest -Uri $ScriptURL -OutFile "$($DestinationFolder.FullName)\$($SaveAsScriptName)" -ErrorAction Stop
Write-Host "Script downloaded successfully saved: [$($DestinationFolder.FullName)\$($SaveAsScriptName)]"
}
catch {
Write-Host "Failed to download the script: $_"
}
}
# Reg2CI (c) 2020 by Roger Zander
# https://github.com/asjimene/GetMSIInfo/blob/master/GetMSIInfo.ps1
# Check if the registry path for * file associations exists, if not, create it.
if ((Test-Path -LiteralPath "HKCU:\Software\Classes\*") -ne $true) {
New-Item "HKCU:\Software\Classes\*" -Force -ErrorAction SilentlyContinue
}
# Check if the 'shell' subkey exists under the * file associations, if not, create it.
if ((Test-Path -LiteralPath "HKCU:\Software\Classes\*\shell") -ne $true) {
New-Item "HKCU:\Software\Classes\*\shell" -Force -ErrorAction SilentlyContinue
}
# Check if the 'Get File Hash Information' subkey exists under 'shell', if not, create it.
if ((Test-Path -LiteralPath "HKCU:\Software\Classes\*\shell\$RightClickMenuName") -ne $true) {
New-Item "HKCU:\Software\Classes\*\shell\$RightClickMenuName" -Force -ErrorAction SilentlyContinue
}
# Set the 'icon' value under 'Get File Hash Information' to a powershell.exe icon
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\*\shell\$RightClickMenuName" -Name 'icon' -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force -ErrorAction SilentlyContinue
# Check if the 'command' subkey exists under 'Get File Hash Information', if not, create it.
if ((Test-Path -LiteralPath "HKCU:\Software\Classes\*\shell\$RightClickMenuName\command") -ne $true) {
New-Item "HKCU:\Software\Classes\*\shell\$RightClickMenuName\command" -Force -ErrorAction SilentlyContinue
}
# Set the default value of the 'Get File Hash Information' key to "Get File Hash Information".
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\*\shell\$RightClickMenuName" -Name '(default)' -Value "$RightClickMenuName" -PropertyType String -Force -ea SilentlyContinue;
# Set the default value of the 'command' key to execute a PowerShell script with the * file as an argument.
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\*\shell\$RightClickMenuName\command" -Name '(default)' -Value "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -Command `"$($DestinationFolder.FullName)\$($SaveAsScriptName)`" -FilePath '%1'" -PropertyType String -Force -ErrorAction SilentlyContinue;
Write-Host "Installation Complete"
})
$MenuItem_Uninstall.add_Click({
Write-Host "Menu Item Uninstall Clicked"
Write-Output "Removing Script from LOCALAPPDATA"
# Remove the script folder from the LOCALAPPDATA folder
Remove-item "$env:LOCALAPPDATA\$([System.IO.Path]::GetFileNameWithoutExtension($ScriptName))" -Force -Recurse -ErrorAction SilentlyContinue
# Reg2CI (c) 2020 by Roger Zander
# https://github.com/asjimene/GetMSIInfo/blob/master/GetMSIInfo.ps1
Write-Output "Cleaning Up Registry"
# Remove the 'Get FIle Hash Information' registry key if it exists
if ((Test-Path -LiteralPath "HKCU:\Software\Classes\*\shell\$RightClickMenuName") -eq $true) {
Remove-Item "HKCU:\Software\Classes\*\shell\$RightClickMenuName" -force -Recurse -ea SilentlyContinue
}
Write-Output "Uninstallation Complete!"
})
$MenuItem_GitHub.add_Click({
# Open Github Project Page
Start-Process "https://github.com/MichaelEscamilla/GetFileHashInformation"
})
$MenuItem_About.add_Click({
# Open Blog
Start-Process "https://michaeltheadmin.com"
})
#### Button Handlers ####
$Button_Copy_Handler = {
# Get the button name
$ButtonName = $_.Source.Name
# Get the property name from the button name by parsing between the underscores
$PropertyName = [regex]::Match($ButtonName, "_(.*?)_").Groups[1].Value
# Get the variable for the textbox with the same name as the property name
$TextboxVariable = Get-Variable -Name "txt_$($propertyName)" -ValueOnly -ErrorAction SilentlyContinue
if ($TextboxVariable) {
Write-Host "Textbox [$($TextboxVariable.Name)] Value Copied to Clipboard : [$($TextboxVariable.Text)]"
# Copy the text from the textbox with the same name as the property name
[System.Windows.Forms.Clipboard]::SetText($TextboxVariable.Text)
}
else {
# Try getting a Listbox variable with the same name as the property name
$ListboxVariable = Get-Variable -Name "lsbox_$($propertyName)" -ValueOnly -ErrorAction SilentlyContinue
if ($ListboxVariable) {
# Check if the item in the listbox contains spaces
if ($lsbox_FilePath.Items[0] -match "\s") {
# Copy the item in the listbox to the clipboard with quotes
[System.Windows.Forms.Clipboard]::SetText("`"$($lsbox_FilePath.Items[0])`"")
Write-Host "Copied to Clipboard: [`"$($lsbox_FilePath.Items[0])`"]"
}
else {
# Copy the item in the listbox to the clipboard without quotes
[System.Windows.Forms.Clipboard]::SetText($lsbox_FilePath.Items[0])
Write-Host "Copied to Clipboard: [$($lsbox_FilePath.Items[0])]"
}
}
}
}
# Get all button variables that contain the word "Copy"
$Buttons = Get-Variable -Name "*Copy" -ValueOnly -ErrorAction SilentlyContinue
foreach ($Button in $Buttons) {
# Add a click event handler to the button
$Button.add_Click($Button_Copy_Handler)
}
#endregion Event Handlers
#Show the WPF Window
$formFileHashProperties.WindowStartupLocation = "CenterScreen"
$formFileHashProperties.ShowDialog() | Out-Null