Get-DirectoryStats: Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
 
(3 dazwischenliegende Versionen des gleichen Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
'''Get the directory size of a local or an remote sytem.'''
+
<span style="font-size:20px;"><span style="color:red">'''-> This function/script is moved to [https://github.com/R-Studio/PSTools GitHub]!'''</span></span><br>
 +
''Get the directory size of a local or an remote sytem.''
 +
 
  
 
<source lang="PowerShell">
 
<source lang="PowerShell">
Zeile 16: Zeile 18:
  
 
             [PSCustomObject]@{
 
             [PSCustomObject]@{
                 Size = $Size
+
                 DirectorySize = $Size
 
                 DirectoryName = $Folder.Name
 
                 DirectoryName = $Folder.Name
 
                 FullPath = $Folder.FullName
 
                 FullPath = $Folder.FullName

Aktuelle Version vom 21. Februar 2020, 16:16 Uhr

-> This function/script is moved to GitHub!
Get the directory size of a local or an remote sytem.


Function Get-DirectoryStats {
    param(
        [Parameter(Position=0)]
        [string] $Path = (PWD).path
    )
 
    process{
 
        $Folders = Get-ChildItem $Path -Directory | Sort-Object
        foreach ($Folder in $Folders) {
            $subFolderItems = Get-ChildItem $Folder.FullName -File -Recurse -Force | Measure-Object -Property Length -Sum | Select-Object Sum
            $Size = [math]::Round($subFolderItems.sum/1GB,2)
 
            [PSCustomObject]@{
                DirectorySize = $Size
                DirectoryName = $Folder.Name
                FullPath = $Folder.FullName
            }
        }
    }
}