Quantcast
Viewing all articles
Browse latest Browse all 21975

Get the largest video files except few directories

Hello everyone,

I am writting a script to get the largest video files on network, except few directories. I have a problem with Get-ChildItem cmd let. I am using include and exclude in pipe and it won't work:/. I had to use a pipe between Get-Item and Get-ChildItem because of excluding directories. It didn't work when I have just GCI. I show you:

$path = Read-Host -Prompt "Type unit what you want to scan"
try{$exclusion = (Read-Host "enter users login what you want to exclude").split(',') | % {$_.trim()}}
catch{
Write-Host "nobody to exclude"
}

##Find out the files greater than equal to below mentioned size
$size = 20MB

##Limit the number of rows
$limit = 20

##Find out the specific extension file
$Extension = @("*.avi","*.mkv","*.mov","*.mp4","*.mpg","*.wmv")

##script to find out the files based on the above input


$largeSizefiles = Get-Item -Path $path -Exclude $exclusion | Get-ChildItem -recurse -Include $Extension | ? { $_.GetType().Name -eq "FileInfo" } | sort-Object -property length -Descending | Select-Object @{Name="SizeInMB";Expression={$_.Length / 1MB}}, FullName -first $limit
$largeSizefiles  |Export-Csv D:\Temp\largeFilesReport.csv

Now it exclude directories what I want but it will find all extensions, not just what I wanted.

Thanks for any advice. I am being quite desperate:)


Viewing all articles
Browse latest Browse all 21975

Trending Articles