SAM Powershell to check for existance of directory on a share and then count the files in it

Version 1

    A client had a requirement of seeing if a file on a share exist, and if it did - count the number of files in it.

     

    Another process creates a directory and puts file into it, each weekday before 9am.  If the directory does not exist or there are zero files in the directory - then the process if broken and needs to be looked into.

     

    This powershell script is executed every two minutes and the associated alert is executed at 9am.   By doing a regular polling, we get an idea of when the process creates the directory and how many files are in there.  I'm sure it can be optimized and shortened. 

     

    $date = Get-Date

    $date = $date.ToString("MMddyyyy")

     

    $path_out = "\\SomewhereOverTheRainbow\OUT\" + $date

     

    If ( (test-path -path $path_out) -eq $True) {

       $filepath = "\\SomewhereOverTheRainbow\OUT\" + $date

       $filetype = "*.*"

       $file_count = [System.IO.Directory]::GetFiles("$filepath").Count

       Write-Host 'Statistic: ' $file_count

    }

     

    If ( (test-path -path $path_out) -eq $False) {

        Write-Host 'Statistic: ' -1

    }

     

    Thanks

    Amit

    Loop1 Systems