-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetFileVersion.ps1
51 lines (41 loc) · 1.45 KB
/
GetFileVersion.ps1
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
$parentFolder = "C:\Program Files\Notepad++"
$outputFile = "$env:USERPROFILE\Documents\FileVersions.csv"
# ArrayList to store file version objects
$fileVersions = New-Object System.Collections.ArrayList
# Function to recursively get file versions
function Get-FileVersion {
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Alias("FullName")]
[string]$Path
)
if (Test-Path -Path $Path -PathType Leaf) {
$fileVersion = (Get-Item $Path).VersionInfo.FileVersion
$fileVersions.Add([PSCustomObject]@{
FileName = Get-Item $Path
FileVersion = $fileVersion
}) | Out-Null
Write-Output "$Path : $fileVersion"
}
}
# Recursive function to process folders
function Process-Folder {
param(
[Parameter(Mandatory = $true)]
[string]$FolderPath
)
# Process files in the current folder
Get-ChildItem -Path $FolderPath -File | ForEach-Object {
Get-FileVersion -Path $_.FullName
}
# Process subfolders
Get-ChildItem -Path $FolderPath -Directory | ForEach-Object {
Process-Folder -FolderPath $_.FullName
}
}
# Start processing from the parent folder
Process-Folder -FolderPath $parentFolder
# Export file versions to CSV
$fileVersions | Export-Csv -Path $outputFile -NoTypeInformation -Encoding UTF8
# Display success message
Write-Host "File versions exported to: $outputFile"