Reputation: 11
I have been trying to create/modify a Powershell script that allows me to automate finding all files across multiple servers larger than 1GB and excluding .ldf and mdf.
I have found a script, but it only looks into the current C Drive and although I've been trying to modify this, I have been unsuccessful.
I'm unsure how to modify this to fit finding multiple servers.
gci -r|sort -descending -property length | select -first 10 name, @{Name="Gigabytes";Expression={[Math]::round($_.length / 1GB, 2)}}
Please help.
Upvotes: 1
Views: 1325
Reputation: 78
Complete Script:
$size=1GB
$path="C:\"
$omit="*.mdf,*.ldf"
Get-ChildItem -Path $path -Exclude $omit -Recurse -OutBuffer 1000|
where {($_.Length -gt $size)}|Select Name, Directory, Length
Sample Output:
Name Directory Length
---- --------- ------
CAP2015-07-29 21-07-08-71.avi C:\ 1216624984
CAP2015-07-29 21-08-17-48.avi C:\Movies 1205696024
Explination of Script:
Variable for controlling search size. Can be KB, MB, GB
$size=1GB
Variable to set base path to search from
$path="C:\"
Variable to set list of excluded extensions
$omit="*.mdf,*.ldf"
Searches through all items from the $Path recursively and returns only files that are over the set size controlled by $size, and omits files listed in $omit.
Get-ChildItem -Path $path -Exclude $omit -Recurse -OutBuffer 1000|
where {($_.Length -gt $size)}|Select Name, Directory, Length
NOTE: The -OutBuffer parameter controls how many items are gathered before continuing. Managing this parameter correctly can greatly increase the speed with which a command completes. This is from a group of parameter called "CommonParameters". Knowing what these are, and how they work is invaluable.
Microsoft Docs about_CommonParameters
Upvotes: 4