Git Product home page Git Product logo

psfoldersize's Introduction

  • ๐Ÿ‘‹ Howdy there - I'm @gngrninja
  • ๐Ÿ“š I like to help others learn to code
  • ๐Ÿค– I also maintain a few Discord bots
  • โ˜• Is my blood
  • ๐ŸŒฑ Let's learn together

psfoldersize's People

Contributors

gngrninja avatar jantari avatar lucascoulson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

psfoldersize's Issues

Get-FolderSize using FolderName parameter fails when a name contains regex symbols

Hi!

I love this tool, and I've been using it for a while now. I ran into a problem when I tried using it on my Program Files. When I enter

Get-FolderSize -FolderName Notepad++

I get the error

parsing "Notepad++" - Nested quantifier +.
At C:\Program Files\WindowsPowerShell\Modules\PSFolderSize\1.6.9\Functions\Private\Get-FolderList.ps1:58 char:21
+                     ($_.BaseName -match "$FolderName") -and
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException

I noticed this is caused by lines 54 and 65 in PSFolderSize/PSFolderSize/Functions/Private/Get-FolderList.ps1.

($_.FullName -match ".+$FolderName.+")   -and 
($_.BaseName -match "$FolderName") -and 

I was able to fix it by using [Regex]::Escape, recommended in https://stackoverflow.com/questions/23651862/powershell-how-to-escape-all-regex-characters-from-a-string.

($_.FullName -match (".+" + [Regex]::Escape($FolderName) + ".+")) -and 
($_.BaseName -match [Regex]::Escape($FolderName)) -and 

Thank you for your time.

Include files in the list

The report is incomplete since it doesn't include the size of the files in $BasePath.

get all of the folder information , but do it for files in $BasePath

#Get folder info / sizes
$folderSize = Get-Childitem -Path $BasePath -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue       
#We use the string format operator here to show only 2 decimals, and do some PS Math.
$folderSizeInMB = "{0:N2} " -f ($folderSize.Sum / 1MB)
$folderSizeInGB = "{0:N2} " -f ($folderSize.Sum / 1GB)

#Here we create a custom object that we'll add to the array
$folderObject = [PSCustomObject]@{
    FolderName    = '"files"'
    'Size(Bytes)' = $folderSize.Sum
    'Size(MB)'    = $folderSizeInMB
    'Size(GB)'    = $folderSizeInGB
}                        

#Add the object to the array
$folderList.Add($folderObject) | Out-Null

Thank you for a very useful tool.

Getting error with Update-TypeData

When I do:
$csv = Import-Csv p:\ComputersAndUsers.csv
foreach ($line in $csv) {
Get-FolderSize -BasePath $line.FullPath -FolderName $line.FolderName
}

I get the folder size but also:
Update-TypeData : Error in TypeData "PS.Folder.List.Result": The member DefaultDisplayPropertySet is already present.
At P:\PowershellScripts\PSFolderSize\PSFolderSize\PSFolderSize.psm1:342 char:5

OmitFolders requires full path(s)

Hi there,

Just wanted to point out the -OmitFolders parameter doesn't appear to work with relative paths, ie. if you CD into a location, and execute Get-FolderSize, the function assumes the current directory, but supplying a list of paths relative to the current directory to this parameter doesn't appear to work.

image

Not sure if you'd consider this a bug or a feature request? :) It might work to just add a call to Resolve-Path when doing your checks on the Omit list.

Hope this helps. Thanks for sharing your code!

Edit: Confirm Resolve-Path works from the input side at least, e.g. Get-FolderSize -OmitFolders (Resolve-Path .git) | Sort-Object SizeBytes -Descending. This, I think would also resolve wildcards, etc. so might be useful in other ways.

i know, i should not use filename with square brackets......

PS C:\temp> Get-FolderSize C:\TEmp\lala*.*
Get-ChildItem : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard character pattern is not
valid: lala[].txt
At C:\Program Files\WindowsPowerShell\Modules\PSFolderSize\1.6.2\Functions\Public\Get-FolderSize.ps1:216 char:23

  • ... olderSize = Get-Childitem -Path $fullPath -Recurse -Force -ErrorActio ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    • FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetChildItemCommand

FolderName Size(MB) Size(GB) FullPath


lala 0,00 0,00 C:\TEmp\lala.txt
lala4e 0,00 0,00 C:\TEmp\lala4e.txt
lala4 0,00 0,00 C:\TEmp\lala4.txt
lala 0,00 0,00 C:\TEmp\lala.zip
lala8 0,00 0,00 C:\TEmp\lala8.txt
lala 0,00 0,00 C:\temp\lala.txt~
lala10 0,00 0,00 C:\TEmp\lala10.txt
lala5 0,00 0,00 C:\TEmp\lala5.txt
lala[] 0,00 0,00 C:\TEmp\lala[].txt

PS C:\temp>

Remove MB and GB from lines in the report

Remove MB and GB from lines in the report.

These mess up importing the data into Excel when I do copy/paste, text to data.
They are already identified as MB and GB in the Item Name, so it's redundant.

Error when `Get-FolderSize` is executed in `/` on linux and Mac

On linux and Mac I've an error showing up when the command is triggered in /.

Setup:

PS /> Get-Host | Select-Object Version

Version
-------
7.1.4
PS /> (Get-Location)

Path
----
/

Command and Error:

PS /> (Get-FolderSize -FolderName 'etc') 
Split-Path: /root/.local/share/powershell/Modules/PSFolderSize/1.7.1/Functions/Private/Get-FolderList.ps1:72
Line |
  72 |          $splitPath = Split-Path -Path $BasePath
     |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot process argument because the value of argument "path"
     | is not valid. Change the value of the "path" argument and run
     | the operation again.

Workaround:

PS /> (Get-FolderSize -FolderName 'etc' -Path '.')

FolderName                     SizeMB       SizeGB       FullPath
----------                     ------       ------       --------
etc                            3.37         0            /etc

Syntax help

Hi,

I am trying to get the summary details of any folders named chrome* (e.g. chrome_data, chrome_downloads). How do I do this please? I seem to get file details when all I want is folder size and file count.

Thanks

Ignore symlinks

Hi!

I tried this module today. It's really great.

One small problem though. I noticed it's showing ~2x the size of a particular folder when compared to the Explorer's Properties dialog. Upon inspecting, I found out that the folder contained symlinks to some other folders.

PSFolderSize should ideally ignore symlinked folders and should not recurse into them to add their size to the output. Otherwise, it's nice!

OmitFolder - Using Wildcards to omit random file names or others.

Hello!

First, thanks for the awesome tool.
Second, this works excellently for almost everything I use it for.

The issue I am running into is that when I am filtering my folder list I am seeing folders and files I don't want to list or, maybe don't care about.
I don't know if this is a supported case as I could not find it, but I wanted to ask.

In the examples below, I wanted to filter out the $ folders ie. C:\$6B9E02DFCC9A4DF7BD9798A64F1E0D85 as well as *.sys, or others, but I was testing $* first.

My query:
PS C:\WINDOWS\system32> Get-FolderSize -Path 'C:\' -OmitFolders 'C:\Temp','C:\Windows','C:\Workspace','C:\Users','$*' | Where-Object {$_.'Size(MB)' -ne 'Empty'}

The wildcard part:
,'$*'

The Output: (Works great just not filtered)

FolderName                     SizeMB       SizeGB       FullPath
----------                     ------       ------       --------
Autodesk                       31168.63     30.44        C:\Autodesk
... Truncated ...
Config.Msi                     4.8          0            C:\Config.Msi
$6B9E02DFCC9A4DF7BD9798A64F1E0 3.31         0            C:\$6B9E02DFCC9A4DF7BD9798A64F1E0D85
$C4D3D31086214879B0EB6F6FB7896 3.31         0            C:\$C4D3D31086214879B0EB6F6FB78961F4
Intel                          1.13         0            C:\Intel
$Windows.~WS                   0.34         0            C:\$Windows.~WS
... Truncated ...
System Volume Information                                C:\System Volume Information

What I had hoped to see:

FolderName                     SizeMB       SizeGB       FullPath
----------                     ------       ------       --------
Autodesk                       31168.63     30.44        C:\Autodesk
... Truncated ...
Config.Msi                     4.8          0            C:\Config.Msi
Intel                          1.13         0            C:\Intel
$Windows.~WS                   0.34         0            C:\$Windows.~WS
... Truncated ...
System Volume Information                                C:\System Volume Information

Question: -AddTotal Results in Different Columns

Hi, I like your script so far. I have a question/confusion. I'm on Windows PowerShell 5.1

If I run Get-FolderSize -BasePath c:\users\myself\downloads, then I get four columns: FolderName, SizeMB, SizeGB, and FullPath.
However, if I run the same and add the -AddTotal switch, then suddenly, I get more columns: FolderName, SizeBytes, SizeKB, SizeMB, SizeGB, FullPath, and HostName. (I also see the total line at the top.)

Is there a reason that "AddTotal" is returning more data fields/properties?

Using Get-Member, it looks like "AddTotal" is returning a "PsCustomObject" as well the other "PS.Folder.List.Result" objects.
Perhaps if the GrandTotal is in the same object format, then there won't be surprise extra results.

Let me know what you think and if I can be of service to make a change.

Leveraging the Size(GB) parameter doesn't work with PSCustomObject

There doesn't seem to be any version of wrapping the Size(GB)|(MB)|(KB)|(Bytes) parameters when used in an array that you can then feed it into a custom object without it choking on the parenthesis in the parameter. Could you possibly change the parameter names to sizeGB, sizeMB, etc.?

Example:
$remotefolders = Get-FolderSize -BasePath $unc -OmitFolders $omitFolder

foreach ($remotefolder in $remotefolders) {        

    $folderObj = New-Object PSObject -Property @{
        folderName  = $remotefolder.folderName
        #folderSizeGB    = $remotefolder.Size(GB)
    }

Parameter 'path' seems to be non-optional

If I leave out the paramater '-Path', the command seems to 'hang'
example:
Get-FolderSize -output csv -Outputpath c:\temp
'hangs', CTRL+C is use to stop it...

but this works:
Get-FolderSize -Path . -output csv -Outputpath c:\temp

CORRECTION: Above statement does not 'hang', but description in help is wrong.
Help states 'The basePath parameter defaults to C:\Users.'
(line#12 in PSFolderSize.psm1, vs line#22 in the same file)

An improvement would be to allow:
Get-FolderSize -output csv c:\temp\output.csv
or
Get-FolderSize -output c:\temp\output.csv

These last 2 command should not give output on screen, but just output stuff to the give filename.

-AddTotal not showing totals

Hi,

Found your module and installed but -AddTotal isn't showing totals for me. Win10, PSCore 7.0.3.
When in C:\temp folder:

Get-FolderSize -AddTotal

FolderName                     SizeMB       SizeGB       FullPath
----------                     ------       ------       --------
Test                           599.93       0.59         C:\temp\Test
Test2                          594.25       0.58         C:\temp\Test2

FolderName : GrandTotal for [C:\temp]
SizeBytes  :
SizeKB     : 0
SizeMB     : 0
SizeGB     : 0
FullPath   : N/A
HostName   : [REDACTED]

same thing happens when the folder itself has files:

Get-FolderSize -AddTotal

FolderName                     SizeMB       SizeGB       FullPath
----------                     ------       ------       --------
Test                           599.93       0.59         C:\temp\Test
Test2                          594.25       0.58         C:\temp\Test2
IMG_0028                       10.37        0.01         C:\temp\IMG_0028.JPG
IMG_0034                       9.12         0.01         C:\temp\IMG_0034.JPG
IMG_0035                       7.77         0.01         C:\temp\IMG_0035.JPG
IMG_0040                       7.63         0.01         C:\temp\IMG_0040.JPG
IMG_0031                       7.23         0.01         C:\temp\IMG_0031.JPG
IMG_0024                       6.84         0.01         C:\temp\IMG_0024.JPG
IMG_0036                       6.62         0.01         C:\temp\IMG_0036.JPG
IMG_0037                       6.18         0.01         C:\temp\IMG_0037.JPG
IMG_0039                       6.14         0.01         C:\temp\IMG_0039.JPG
IMG_0025                       5.91         0.01         C:\temp\IMG_0025.JPG
IMG_0023                       5.75         0.01         C:\temp\IMG_0023.JPG
IMG_0018                       5.38         0.01         C:\temp\IMG_0018.JPG
IMG_0017                       5.17         0.01         C:\temp\IMG_0017.JPG
IMG_0019                       4.86         0            C:\temp\IMG_0019.JPG
IMG_0016                       4.48         0            C:\temp\IMG_0016.JPG
IMG_0020                       4.44         0            C:\temp\IMG_0020.JPG
IMG_0021                       3.96         0            C:\temp\IMG_0021.JPG

FolderName : GrandTotal for [C:\temp]
SizeBytes  :
SizeKB     : 0
SizeMB     : 0
SizeGB     : 0
FullPath   : N/A
HostName   : [REDACTED]

Gets all folders, not the one specified

$basepath = "c:\ApplicationFolder"
$folder = "Data"
The command: "$Usage = Get-foldersize -basepath $BasePath -foldername $Folder"

This gives me the information for; Data, Data1, Data2 and so on. Iยดm reading the help file, but as far as i can tell it should give me only the specified folder.

DE number formatting

From PS Gallery comment:

I was getting an error with DE number format where decimals are ',' separator. TT.CCC,DD, so I had to edit the .ps1 files and remove the [double] cast added in the version 1.5

In any case, thanks for the script, it was really helpful!

Output sorting

Would love to get possibility to sort with another -output parameter by specified column, e.g. "-OutputSort FolderName".
"Sort-Object 'FolderName' " only effects the PS output, not the *.csv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.