This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Powershell file size monitors

This is probably an easy one, I just admittedly don't know the first thing about PowerShell but I need to get some monitors built.

I've got some commands that do something close to what I want but I don't know how to make them output as statistics so SAM can use them.

One is to check directory size, the other is to check the filesize of the largest file in the directory.

This is what I have currently:

Directory size:  Get-ChildItem C:\Windows | Measure-Object -property length –sum

Largest file in directory:  Get-ChildItem c:\Windows | Sort Length -desc | Select-Object -first 1

How do I get them to give me statistics instead of the current output?

Thanks!

  • SAM is expecting a Statistic, and an optional message.  Something like this should work...

    $path = 'c:\temp'

    $file = Get-ChildItem $path | Sort Length -Descending | Select-Object -First 1

    $dir_size = Get-ChildItem $path | Measure-Object -Property Length -Sum

    'Message.LargestFile: ' + $file.Name

    'Message.DirSize: ' + $dir_size.Sum

    'Statistic.LargestFile: ' + $file.Length

    'Statistic.DirSize: ' + $dir_size.Sum

    As a side note, this will only be the size of the files in the $path directory, and the largest file in that same path, it does not include the sub-directories because you missed -recurse off off the Get-ChildItem (this may be intentional.

    Edit:

    If you wanted something of a more manageable number as well, you can use the PowerShell divisors for sizes, like $file.Length/1MB to convert it into MBs