Solved

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

Posted on 2016-07-18
4
40 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 17

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 84

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 80

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Synchronize a new Active Directory domain with an existing Office 365 tenant
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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