Path Folder count monitoring

Hi All,

I am looking for a PowerShell script that can check path and count how many folder available in that path

example i have a path : \\XXXXSSQLP01\Team\work 
if we have 2 or more folders available in that path alert will triggred

can any one help in this


Sumit Goel

  • This is more than an alert.  You need to first build a monitor in SAM to check for the folder count.  There's an out of the box one that does it using PowerShell, but this is basically what it does.

    $Folders = Get-ChildItem -path \\ServerName\SharedFolder\ChildPath -Recurse -Folder
    if ( $Folders.Count -ge 2 ) {
        Write-Host "Message: We found $( $Folders.Count ) Folders - that's bad"
        Write-Host "Statistic: $( $Folders.Count )"
    else {
        Write-Host "Message: We found $( $Folders.Count ) Folders - that's good"
        Write-Host "Statistic: $( $Folders.Count )"

    Then you just need to alter the definition of the component so that if the statistic is 2 or more, it returns a critical status.

    Then the alert is easy: Alert when a component name is "Whatever you called this component" and the status is "Critical" fire an alert.

  • sorry but i am looking for file count monitoring for latest date

    i have prepared some thing but not able to print latest count with date

    get-childitem '\\NJIOILMSSQLU01\ilmsdata\VendorExport\NachaExport' |
    select @{n='Date';e={$_.LastWriteTime.ToShortDateString()}} |
    Group-Object Date |
    Format-Table Name, Count

    IF ($Count -gt 2)
    $Message = 'there are wrong/duplicate files generated'
    Write-Host 'Statistic.Status: '2
    Write-Host 'Message.Status: '$Message
    $Message = 'there are no wrong/duplicate files generated'
    Write-Host 'Statistic.Status: '1
    Write-Host 'Message.Status: '$Message

    ######## End Script #########

  • Are you only looking for files after "today" or in the last 24 hours or something else?  Please be as specific as possible so we can help craft this.

  • for current date file count
    Name Count
    5/31/2022 2

Reply Children