-
Notifications
You must be signed in to change notification settings - Fork 4
/
Get-VideoFileInfo.ps1
287 lines (248 loc) · 10.9 KB
/
Get-VideoFileInfo.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
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
<#######<Script>#######>
<#######<Header>#######>
# Name: Get-VideoFileInfo
# Copyright: Gerry Williams (https://automationadmin.com)
# License: MIT License (https://opensource.org/licenses/mit)
# Script Modified from: n/a
<#######</Header>#######>
<#######<Body>#######>
Function Get-VideoFileInfo
{
<#
.Synopsis
Given a source directory, this function will recursively get all the video files and display their resolutions.
.Description
Given a source directory, this function will recursively get all the video files and display their resolutions.
.Parameter Path
Mandatory - The source folder where your video files reside.
.Parameter OutputFile
Mandatory - The destination file name csv.
.Example
Get-VideoFileInfo -Path "E:\videos" -OutputFile "C:\temp\videos.csv"
Given a source directory, this function will recursively get all the video files and display their resolutions.
.Notes
Source info: https://gallery.technet.microsoft.com/scriptcenter/Retrieve-file-metadata-6814c8ba
#>
[Cmdletbinding()]
Param
(
[Parameter(Position = 0, Mandatory = $True)]
[String]$Path,
[Parameter(Position = 1, Mandatory = $True)]
[String]$OutFile
)
Begin
{
####################<Default Begin Block>####################
# Force verbose because Write-Output doesn't look well in transcript files
$VerbosePreference = "Continue"
[String]$Logfile = $PSScriptRoot + '\PSLogs\' + (Get-Date -Format "yyyy-MM-dd") +
"-" + $MyInvocation.MyCommand.Name + ".log"
Function Write-Log
{
<#
.Synopsis
This writes objects to the logfile and to the screen with optional coloring.
.Parameter InputObject
This can be text or an object. The function will convert it to a string and verbose it out.
Since the main function forces verbose output, everything passed here will be displayed on the screen and to the logfile.
.Parameter Color
Optional coloring of the input object.
.Example
Write-Log "hello" -Color "yellow"
Will write the string "VERBOSE: YYYY-MM-DD HH: Hello" to the screen and the logfile.
NOTE that Stop-Log will then remove the string 'VERBOSE :' from the logfile for simplicity.
.Example
Write-Log (cmd /c "ipconfig /all")
Will write the string "VERBOSE: YYYY-MM-DD HH: ****ipconfig output***" to the screen and the logfile.
NOTE that Stop-Log will then remove the string 'VERBOSE :' from the logfile for simplicity.
.Notes
2018-06-24: Initial script
#>
Param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[PSObject]$InputObject,
# I usually set this to = "Green" since I use a black and green theme console
[Parameter(Mandatory = $False, Position = 1)]
[Validateset("Black", "Blue", "Cyan", "Darkblue", "Darkcyan", "Darkgray", "Darkgreen", "Darkmagenta", "Darkred", `
"Darkyellow", "Gray", "Green", "Magenta", "Red", "White", "Yellow")]
[String]$Color = "Green"
)
$ConvertToString = Out-String -InputObject $InputObject -Width 100
If ($($Color.Length -gt 0))
{
$previousForegroundColor = $Host.PrivateData.VerboseForegroundColor
$Host.PrivateData.VerboseForegroundColor = $Color
Write-Verbose -Message "$(Get-Date -Format "yyyy-MM-dd hh:mm:ss tt"): $ConvertToString"
$Host.PrivateData.VerboseForegroundColor = $previousForegroundColor
}
Else
{
Write-Verbose -Message "$(Get-Date -Format "yyyy-MM-dd hh:mm:ss tt"): $ConvertToString"
}
}
Function Start-Log
{
<#
.Synopsis
Creates the log file and starts transcribing the session.
.Notes
2018-06-24: Initial script
#>
# Create transcript file if it doesn't exist
If (!(Test-Path $Logfile))
{
New-Item -Itemtype File -Path $Logfile -Force | Out-Null
}
# Clear it if it is over 10 MB
[Double]$Sizemax = 10485760
$Size = (Get-Childitem $Logfile | Measure-Object -Property Length -Sum)
If ($($Size.Sum -ge $SizeMax))
{
Get-Childitem $Logfile | Clear-Content
Write-Verbose "Logfile has been cleared due to size"
}
Else
{
Write-Verbose "Logfile was less than 10 MB"
}
Start-Transcript -Path $Logfile -Append
Write-Log "####################<Function>####################"
Write-Log "Function started on $env:COMPUTERNAME"
}
Function Stop-Log
{
<#
.Synopsis
Stops transcribing the session and cleans the transcript file by removing the fluff.
.Notes
2018-06-24: Initial script
#>
Write-Log "Function completed on $env:COMPUTERNAME"
Write-Log "####################</Function>####################"
Stop-Transcript
# Now we will clean up the transcript file as it contains filler info that needs to be removed...
$Transcript = Get-Content $Logfile -raw
# Create a tempfile
$TempFile = $PSScriptRoot + "\PSLogs\temp.txt"
New-Item -Path $TempFile -ItemType File | Out-Null
# Get all the matches for PS Headers and dump to a file
$Transcript |
Select-String '(?smi)\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*([\S\s]*?)\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*' -AllMatches |
ForEach-Object {$_.Matches} |
ForEach-Object {$_.Value} |
Out-File -FilePath $TempFile -Append
# Compare the two and put the differences in a third file
$m1 = Get-Content -Path $Logfile
$m2 = Get-Content -Path $TempFile
$all = Compare-Object -ReferenceObject $m1 -DifferenceObject $m2 | Where-Object -Property Sideindicator -eq '<='
$Array = [System.Collections.Generic.List[PSObject]]@()
foreach ($a in $all)
{
[void]$Array.Add($($a.InputObject))
}
$Array = $Array -replace 'VERBOSE: ', ''
Remove-Item -Path $Logfile -Force
Remove-Item -Path $TempFile -Force
# Finally, put the information we care about in the original file and discard the rest.
$Array | Out-File $Logfile -Append -Encoding ASCII
}
Start-Log
Function Set-Console
{
<#
.Synopsis
Function to set console colors just for the session.
.Description
Function to set console colors just for the session.
This function sets background to black and foreground to green.
Verbose is DarkCyan which is what I use often with logging in scripts.
I mainly did this because darkgreen does not look too good on blue (Powershell defaults).
.Notes
2017-10-19: v1.0 Initial script
#>
Function Test-IsAdmin
{
<#
.Synopsis
Determines whether or not the user is a member of the local Administrators security group.
.Outputs
System.Bool
#>
[CmdletBinding()]
$Identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$Principal = new-object System.Security.Principal.WindowsPrincipal(${Identity})
$IsAdmin = $Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
Write-Output -InputObject $IsAdmin
}
$console = $host.UI.RawUI
If (Test-IsAdmin)
{
$console.WindowTitle = "Administrator: Powershell"
}
Else
{
$console.WindowTitle = "Powershell"
}
$Background = "Black"
$Foreground = "Green"
$Messages = "DarkCyan"
$Host.UI.RawUI.BackgroundColor = $Background
$Host.UI.RawUI.ForegroundColor = $Foreground
$Host.PrivateData.ErrorForegroundColor = $Messages
$Host.PrivateData.ErrorBackgroundColor = $Background
$Host.PrivateData.WarningForegroundColor = $Messages
$Host.PrivateData.WarningBackgroundColor = $Background
$Host.PrivateData.DebugForegroundColor = $Messages
$Host.PrivateData.DebugBackgroundColor = $Background
$Host.PrivateData.VerboseForegroundColor = $Messages
$Host.PrivateData.VerboseBackgroundColor = $Background
$Host.PrivateData.ProgressForegroundColor = $Messages
$Host.PrivateData.ProgressBackgroundColor = $Background
Clear-Host
}
Set-Console
####################</Default Begin Block>####################
}
Process
{
$Objshell = New-Object -Comobject Shell.Application
$Filelist = [System.Collections.ArrayList]@()
$Attrlist = @{}
$Details = ( "Frame Height", "Frame Width", "Frame Rate" )
$Objfolder = $Objshell.Namespace($Path)
For ($Attr = 0 ; $Attr -Le 500; $Attr++)
{
$Attrname = $Objfolder.Getdetailsof($Objfolder.Items, $Attr)
If ( $Attrname -And ( -Not $Attrlist.Contains($Attrname) ))
{
$Attrlist.Add( $Attrname, $Attr )
}
}
Get-ChildItem $Path -Recurse -Directory | Foreach-Object {
$Objfolder = $Objshell.Namespace($_.Fullname)
Foreach ($File In $Objfolder.Items())
{
Foreach ( $Attr In $Details)
{
$Attrvalue = $Objfolder.Getdetailsof($File, $Attrlist[$Attr])
If ( $Attrvalue )
{
Add-Member -Inputobject $File -Membertype Noteproperty -Name $("A_" + $Attr) -Value $Attrvalue
}
}
[Void]$Filelist.Add($File)
$Filelist.Count
}
}
$Filelist | Export-Csv $OutFile -Delimiter ','
$Filelist | Format-Table
}
End
{
Stop-log
}
}
<#######</Body>#######>
<#######</Script>#######>