Search code examples
powershellservice

If count of files in directory greater than x then restart service


Good Day,

I am seeking a method to have a scheduled task run frequently detecting if over 12 files in a designated folder (Let's say C:\Q) then reboot specified Windows Services.

I believe this would be possible with PowerShell but perhaps also possible with a batch/CMD file?

Thank you for your feedback.


Solution

  • This is very possible with PowerShell.

    If ((Get-ChildItem "C:\Q").Count -gt 12){
        # Restart you service here
        # The cmdlets Stop-service and Start-Service should help you
    }