none
search files from multiple servers from get-childitem RRS feed

  • Question

  • 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
    }

    Monday, February 9, 2015 8:46 PM

Answers

  • 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 9, 2015 9:24 PM
    • Marked as answer by Mr. Raj Friday, February 13, 2015 2:00 PM
    Monday, February 9, 2015 9:23 PM
  • 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
    Friday, February 13, 2015 2:00 PM

All replies

  • 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 9, 2015 9:24 PM
    • Marked as answer by Mr. Raj Friday, February 13, 2015 2:00 PM
    Monday, February 9, 2015 9:23 PM
  • 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:

    Tuesday, February 10, 2015 3:56 PM
  • 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.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, February 10, 2015 4:08 PM
    Moderator
  • any other guidance or link to help me ..
    Tuesday, February 10, 2015 5:54 PM
  • Try the Learn link at the top of this forum.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, February 10, 2015 5:59 PM
    Moderator
  • 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.

    Thursday, February 12, 2015 2:42 PM
  • Look at your loop logic and where you're doing your export.

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Thursday, February 12, 2015 2:48 PM
    Moderator
  • I did not understand your point here 
    Thursday, February 12, 2015 3:55 PM
  • 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?


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Thursday, February 12, 2015 3:58 PM
    Moderator
  • 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

    Thursday, February 12, 2015 5:07 PM
  • 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?


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Thursday, February 12, 2015 5:09 PM
  • Are you referring this line : What's going to be in that file when the loop finishes?
    Thursday, February 12, 2015 5:16 PM
  • If you need someone to write a script for you, you can request it here:

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


    -- Bill Stewart [Bill_Stewart]

    Thursday, February 12, 2015 5:21 PM
    Moderator
  • 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
    Friday, February 13, 2015 2:00 PM