PowerShell – Find top 10 Largest files of a local or remote Drive

Name of the function: Get-LargestFile

The Input parameters are ServerName and Drive.

Function call

PS:\>Get-LargestFile -server HQDB001-drive e

In this case HQDB001[ServerName] and E[Drive]

****************************

Code:-

***********************

Function Get-LargestFile
{
Param([String]$server,[char]$drive)
Get-ChildItem \\$server\$drive$ -recurse -force -ErrorAction SilentlyContinue | Select-object Name,DirectoryName, @{Label=’Size’;Expression={($_.Length/1GB).ToString(‘F04′)}} | Sort Size -descending | select -First 10
}

Advertisements

About Prashanth Jayaram

DB Technologist, Author, Blogger, Operations-Mgr at CTS, Automation Expert, Technet WIKI Ninja, MVB and Powershell Geek You can connect me via https://social.technet.microsoft.com/profile/prashanth jayaram/ http://www.sqlshack.com/author/prashanth/ https://www.tumblr.com/blog/prashantjayaram http://www.sqlservercentral.com/blogs/powersql-by-prashanth-jayaram/ http://www.toadworld.com/members/prashanthjayaram/ My Articles are published in following sites http://www.ssas-info.com/analysis-services-articles/ http://db-pub.com/ http://www.sswug.org/sswugresearch/community/
This entry was posted in PowerShell. Bookmark the permalink.

2 Responses to PowerShell – Find top 10 Largest files of a local or remote Drive

  1. Brian Cassidy says:

    Thank you very much for this function. I have found that the (‘F04′) needs to be entered as (‘F04’) for this function to work properly.

    • Brian Cassidy says:

      Somehow my identified correction has gotten transposed from single quotes to what you see in my original post . The F04 should be single quoted.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s