search files from multiple servers from get-childitem

Hi 

I have created below script to find out all files from remote computers which have extensions like jpg and all. I am able to find 

But I want to search files which are more than 10 MB and length header should be like Size in MB" instead of length.

Please help or guide me..

Import-Csv .\serverlist.csv | Foreach {

$searchservername = $_.rebootserveranme
$path = "c:\","D:\"
$size = 10MB
$extensions = '*.jpg*', '*.jpeg*', '*.mpeg', '*.pdf', '*.avi', '*.mov'
Get-ChildItem -Path $path -Include $extensions -Recurse -Force | select fullname,CreationTime,LastAccessTime,LastWriteTime,PSChildName,extension,length | export-CSv "files-$searchservername.csv" -Notypeinformation
}

February 9th, 2015 11:46pm

Try something like:

$path = "c:\temp\"
$extensions = @("*.jpg", "*.jpeg")
Get-ChildItem -Path $path -Include $extensions -Recurse | Where-Object { $_.Length -gt 10MB }


  • Edited by Jalapeno42 Monday, February 09, 2015 9:24 PM
  • Marked as answer by Mr. Raj Friday, February 13, 2015 2:00 PM
Free Windows Admin Tool Kit Click here and download it now
February 10th, 2015 12:23am

Also this:

https://technet.microsoft.com/en-us/library/ff730948.aspx

February 10th, 2015 12:26am

I need to get in output with workstation name for which I am querying.

so that I  in CSV file output should be like below:

Free Windows Admin Tool Kit Click here and download it now
February 10th, 2015 6:56pm

You can request scripts at the script request page here:

https://gallery.technet.microsoft.com/scriptcenter/site/requests

This isn't the right place to ask others to write code to spec.

February 10th, 2015 7:08pm

any other guidance or link to help me ..
Free Windows Admin Tool Kit Click here and download it now
February 10th, 2015 8:54pm

Try the Learn link at the top of this forum.

February 10th, 2015 8:59pm

Hi

Now I am getting computer name as per requirment. But only issue is that this script giving me output only for one
computer name even i have multiple computer name in my CSV file.


Import-Csv "D:\test\serverlist.csv" | Foreach {
$server = $_.servername
$Drives = "c:\","D:\"
$size = 10KB
$extensions = @("*.jpg", "*.jpeg", "*.mpeg", "*.asx", "*.wm", "*.wmx", "*.wav", "*.mp3", "*.m3u", "*.aac", "*.wm", "*.aac", "*.wmv", "*.asf", "*.m2ts", "*.m2t", "*.mov", "*.qt", "*.avi", "*.wtv", "*.dvr-ms", "*.mp4", "*.mov", "*.m4v", "*.mpeg", "*.mpg", "*.mpe", "*.m1v", "*.mp2", "*.mpv2", "*.mod", "*.vob", "*.m1v", "*.avi", "*.jpg", "*.jpeg", "*.hdp", "*.wdp", "*.tif", "*.tiff", "*.raw", "*.gif", "*.bmp", "*.png")
$file = Get-ChildItem -Path $Drives -Include $extensions -Recurse -ErrorAction SilentlyContinue  -Force | 
where-Object {$_.length -gt $size} | 
Select-Object @{Name="computername";Expression{$server}},Name,CreationTime,@{Name="SizeInMB";Expression{$_.Length / 1MB}},LastAccessTime,LastWriteTime,extension,@{Name= "FilePath";Expression={$_.FullName}} | 
Export-CSV findfiles.csv -notypeinformation
}

Please guide or help me to get all computer name data.

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 5:42pm

Look at your loop logic and where you're doing your export.
February 12th, 2015 5:48pm

I did not understand your point here 
Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 6:55pm

Your export is inside the loop, so every time it goes through the loop it does a new export.

 What's going to be in that file when the loop finishes?

February 12th, 2015 6:58pm

It gives me only one computername data.. not for next computername

My CSV file format is like below

servername

server1

server2

it give me only server1 data

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 8:07pm

It gives me only one computername data.. not for next computername

My CSV file format is like below

servername

server1

server2

it give me only server1 data

And what does that suggest?

February 12th, 2015 8:09pm

Are you referring this line : What's going to be in that file when the loop finishes?
Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 8:16pm

If you need someone to write a script for you, you can request it here:

https://gallery.technet.microsoft.com/scriptcenter/site/requests

February 12th, 2015 8:21pm

I have resolved it by my self.. with below codes.

Thanks to all..

Import-Csv "D:\test\serverlist.csv" | Foreach {
$server = $_.servername
$Drives = "c:\","D:\"
$size = 10KB
$extensions = @("*.jpg", "*.jpeg", "*.mpeg", "*.asx", "*.wm", "*.wmx", "*.wav", "*.mp3", "*.m3u", "*.aac", "*.wm", "*.aac", "*.wmv", "*.asf", "*.m2ts", "*.m2t", "*.mov", "*.qt", "*.avi", "*.wtv", "*.dvr-ms", "*.mp4", "*.mov", "*.m4v", "*.mpeg", "*.mpg", "*.mpe", "*.m1v", "*.mp2", "*.mpv2", "*.mod", "*.vob", "*.m1v", "*.avi", "*.jpg", "*.jpeg", "*.hdp", "*.wdp", "*.tif", "*.tiff", "*.raw", "*.gif", "*.bmp", "*.png")
Get-ChildItem -Path $Drives -Include $extensions -Recurse -ErrorAction SilentlyContinue  -Force | 
where-Object {$_.length -gt $size} | 
Select-Object @{Name="computername";Expression{$server}},Name,CreationTime,@{Name="SizeInMB";Expression{$_.Length / 1MB}},LastAccessTime,LastWriteTime,extension,@{Name= "FilePath";Expression={$_.FullName}} 
} | Export-CSV findfiles.csv -notypeinformation

  • Marked as answer by Mr. Raj Friday, February 13, 2015 2:00 PM
Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 5:00pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics