1: <#
2: 用途:
3: 根据指定的路径和文件类型查找出文件,显示其完整路径以及大小
4: 使用方法:
5: Get-FilewithExtension -path path1,path2,path3 -extension .bak,.csv -CsvFilePath e:\result.csv
6: #>
7: function Get-FilewithExtension
8: ([array] $Path, #指定要查询的路径
9: [array] $Extension, #指定文件类型
10: [string]$CsvFilePath) #指定导出结果文件
11: {
12: $result = @()
13: $file = Get-ChildItem -Path $Path -Recurse |Where-Object {$_.PSIsContainer -eq $false}
14: foreach($i in $file)
15: {
16:
17: if($Extension.Contains($i.Extension) -eq $true)
18: {
19: $obj = New-Object -TypeName PSObject
20: $obj | Add-Member NoteProperty 文件路径 $i.FullName
21: $obj | Add-Member NoteProperty 文件大小 $i.Length
22: $result +=$obj
23: }
24:
25: }
26: $result |Export-Csv $CsvFilePath -Encoding OEM -NoTypeInformation
27: }