Solved

50 GB file Audit Script using powershelll not showing exact file path

Posted on 2016-07-18
4
33 Views
1 Endorsement
Last Modified: 2016-07-19
The below script has capability to search files more than 50GB in size under the path F:\Lotus\Domino\Data, but its not giving the complete path where the file exists. For example one of the file is under a sub-folder it still shows was found under F:\Lotus\Domino\Data... If any one can help me to add what is missing will be of a great help and I need this ASAP. Also I want to understand the complete script how it works.
Please help me friends.

$ServerFile = 'C:\Temp\Servers.txt'
$LocalFolder = 'F:\Lotus\Domino\Data'
$FileSize = 50 * 1GB
$ResultFile = 'C:\Temp\FileSize.csv'
Get-Content $ServerFile | ForEach-Object {
      $ComputerName = $_
      Get-ChildItem "\\$_\$($LocalFolder.Replace(':', '$'))" -Recurse |
            Where-Object {$_.Length -gt $FileSize} |
            Select-Object -Property `
                  @{n="ComputerName"; e={$ComputerName}},
                  @{n="Name"; e={"$($LocalFolder)\$($_.Name)"}},
                  @{n="SizeMB"; e={[math]::Round($_.Length / 1MB, 3)}}
} | Export-Csv -NoTypeInformation -Path $ResultFile
1
Comment
Question by:PavanPA
4 Comments
 
LVL 16

Expert Comment

by:Learnctx
ID: 41718127
If you want the full path then use the fullname property instead of name.

$ServerFile = 'C:\Temp\Servers.txt'
$LocalFolder = 'F:\Lotus\Domino\Data'
$FileSize = 50 * 1GB
$ResultFile = 'C:\Temp\FileSize.csv'
Get-Content $ServerFile | ForEach-Object {
      $ComputerName = $_
      Get-ChildItem "\\$_\$($LocalFolder.Replace(':', '$'))" -Recurse |
            Where-Object {$_.Length -gt $FileSize} |
            Select-Object -Property `
                  @{n="ComputerName"; e={$ComputerName}},
                  FullName,
                  @{n="SizeMB"; e={[math]::Round($_.Length / 1MB, 3)}}
} | Export-Csv -NoTypeInformation -Path $ResultFile

Open in new window

Also this seems wrong.

Get-ChildItem "\\$_\$($LocalFolder.Replace(':', '$'))" -Recurse

Open in new window

Should it be this instead? Granted, I have not run your script so just running it over by eye.

Get-ChildItem "\\$_\$($LocalFolder.Replace('$', '$'))" -Recurse

Open in new window

2
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41718193
I think I recognize my handiwork there. You don't get the full name because the original version of the script wasn't meant to search recursively.
$ServerFile = 'C:\Temp\Servers.txt'
$LocalFolder = 'F:\Lotus\Domino\Data'
$FileSize = 50 * 1GB
$ResultFile = 'C:\Temp\FileSize.csv'
Get-Content $ServerFile | % {
	$ComputerName = $_
	$SearchRoot = "\\$_\$($LocalFolder.Replace(':', '$'))"
	Get-ChildItem $SearchRoot -Recurse |
		Where-Object {$_.Length -gt $FileSize} |
		Select-Object -Property `
			@{n="ComputerName"; e={$ComputerName}},
			@{n="Name"; e={$_.FullName.Replace($SearchRoot, $LocalFolder)}},
			@{n="SizeMB"; e={[math]::Round($_.Length / 1MB, 3)}}
} | Export-Csv -NoTypeInformation -Path $ResultFile

Open in new window

2
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 41718224
$ServerFile = 'C:\Temp\Servers.txt'
$LocalFolder = 'd:\Hyper-v\'
$FileSize = 50 * 1GB #50 GB
$ResultFile = 'C:\Temp\FileSize.csv'
remove-item $resultfile -ErrorAction SilentlyContinue
$myobj = @()
$servers = Get-Content $ServerFile
ForEach ($Server in $Servers) {
    $filepath = "\\$server\$($LocalFolder.Replace(':', '$'))"
    $Files = Get-ChildItem  $filepath -Recurse -File
    ForEach ($file in $Files)
        {
        if ($file.length -ge $FileSize)
            {
            $obj = new-object -TypeName PSObject      
            $obj | add-member -MemberType NoteProperty -Name 'ComputerName' -Value $Server
            $obj | add-member -MemberType NoteProperty -Name 'Name' -Value $file.FullName.replace($filepath, $LocalFolder)
            $obj | add-member -MemberType NoteProperty -Name 'SizeMB' -Value ([math]::Round($file.Length / 1MB, 3))
            $myobj +=  $obj
        } 
}        
}
if ($myobj.Count -gt 0) {
    $myobj | Export-Csv -NoTypeInformation -Path $ResultFile 
    }
 else {
    write-output 'No Files over 50 GB'
    }
get-content $resultfile

Open in new window

2
 

Author Closing Comment

by:PavanPA
ID: 41718230
The script worked for me as requested and I am very thankful and will always take help from oBdA when required. :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now