-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoviescanner.ps1
56 lines (44 loc) · 1.95 KB
/
Moviescanner.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
52
53
54
55
56
# Functie om recursief te zoeken voor video bestanden op de geselecteerde schijf.
function Search-MovieFiles {
param (
[string]$Drive
)
$movieFormats = "*.mov","*.mpeg","*.mpg","*.divx","*.mkv","*.avi","*.mp4"
$movieFiles = @()
foreach ($format in $movieFormats) {
$movieFiles += Get-ChildItem -Path $Drive -Recurse -Filter $format -ErrorAction SilentlyContinue | Select-Object FullName, Length, @{Name="Format";Expression={$format.TrimStart("*.")}}
}
return $movieFiles
}
# Functie om een export txt file aan te maken
function Create-TextReport {
param (
[array]$MovieFiles,
[string]$Drive
)
$reportContent = @()
$reportContent += "Movie files found on drive " + $Drive + "`r`n"
foreach ($movie in $MovieFiles) {
$fileSizeMB = [math]::Round(($movie.Length / 1MB), 2)
$fileInfo = "Location: $($movie.FullName | Split-Path -Parent), Name: $($movie.FullName | Split-Path -Leaf), Size: $fileSizeMB MB, File type: $($movie.Format)"
$reportContent += $fileInfo
}
$reportContent += "`r`nTotal number of movie files found: $($MovieFiles.Count)"
$reportFileName = "movie_scan_$Drive_" + (Get-Date).ToString("yyyyMMdd_HHmmss") + ".txt"
$reportPath = [System.IO.Path]::Combine([Environment]::GetFolderPath("Desktop"), $reportFileName)
$reportContent | Out-File -FilePath $reportPath
Write-Output "Text report saved on the desktop."
}
# Hoofd script
$drives = Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} | Select-Object -ExpandProperty DeviceID
$selectedDrive = $drives | Out-GridView -Title "Select a drive" -OutputMode Single
if ($selectedDrive) {
$movieFiles = Search-MovieFiles -Drive $selectedDrive
if ($movieFiles) {
Create-TextReport -MovieFiles $movieFiles -Drive $selectedDrive
} else {
Write-Output "No movie files found on drive $selectedDrive."
}
} else {
Write-Output "No drive selected."
}