Note: The above command calculate folder size only using first level files, it will not include the nested folder files. Write-Host 'Folder Size(MB): '$folderSizeMB 'Total Files: '$filesCount -ForegroundColor Green $folderInfo = Get-ChildItem C:Scripts | Measure-Object -Property Length -Sum
You can’t directly find the size of a directory, but you can indirectly determine the size of a folder by getting files using the cmdlets Get-ChildItem and Measure-Object. Write-Host 'Size(GB): '$sizeGB -ForegroundColor Green Write-Host 'Size(MB): '$sizeMB -ForegroundColor Green Write-Host 'Size(KB): '$sizeKB -ForegroundColor Green We can use the function ::Round to convert the byte value to desired unit like KB, MB and GB. Write-Host 'Size(Bytes): '$size -ForegroundColor Green The below command returns the size of the given file as bytes.
We can use the PowerShell cmdlet Get-Item to get file information including size of a file, we can also the the same command to get folder or directory information but it will return the size of folder as folder is determined by size of all the files that are inside the particular directory.