![]() Measure-Object -Sum Length | Select-Object Expression= In addition, while we are at it, let us use the names “Files” and “Size” instead of “Count” and “Sum.” To do this, I am going to output a custom object like this: This is good as far as it goes, but I wanted my output object to include the directory’s name. The end result is a new output object that contains only those two properties. Now we are using Select-Object to select (hence the name) only the two properties we care about. Get-ChildItem | Measure-Object -Sum Length | Select-Object Count, Sum However, we only care about the Count and Sum properties, so let us refine our command a bit: The Measure-Object cmdlet outputs an object with five properties (including Count, Average, and Sum). In other words, this command tells you the count and sum of the sizes of all the files in the current directory. Get-ChildItem outputs a list of items in the current location (in files and folders, if your current location is in a file system), and Measure-Object uses this list as input and adds together every input object’s Length property (file size). ![]() Get-ChildItem | Measure-Object -Sum Length A simple example would be a command like this: In this case, I know that Windows PowerShell can find files ( Get-ChildItem), and I know that it can count objects and sum a property on objects. The trick is learning how to combine the tools to get the results you need. If you have worked with Windows PowerShell for any length of time, you know that it provides a pretty comprehensive set of tools. For example, what if you need the size for 100 different folders? As with all things GUI, this does not scale well. ![]() You have probably asked this question hundreds of times, “How big is that folder?” Of course, the typical GUI way to find out is to right-click the folder in Windows Explorer and open the folder’s properties. Bill Stewart is a scripting guru and a moderator for the Official Scripting Guys forum. Microsoft Scripting Guy, Ed Wilson, is here. Summary: Guest blogger, Bill Stewart, discusses a Windows PowerShell function to determine folder size. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |