Count imported Files

  • I need following in the script.

    - Compair the Field "Count_import" of delivered with "Count_fault" document and send a E-Mail if there is a difference or Count_Fault>0

    have write a script, which works fine but what is missing is, when field Count_Fault > 0, then a email should be sent to me.

    There is my Script which checks two Directory and write it to DB Tabel TBL_Import.

    Table:TBL_Import

    ********************************************

    IDX Count_Import Count_Fault Date_Import Send_Message

    1 182 0 29.06.2013 21:11:10

    MyScript

    *****************************************************

    $strFilter = "(&(objectCategory=person)(objectClass=user))"

    $objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://dc=dom,dc=de")

    $Searcher = New-Object System.DirectoryServices.DirectorySearcher

    $Searcher.SearchRoot = $objDomain

    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher

    $objSearcher.SearchRoot = $objDomain

    $objSearcher.PageSize = 200

    $objSearcher.Filter = $strFilter

    $objSearcher.SearchScope = "Subtree"

    $colProplist = "Count_Import", "Count_Fault", "Date_Import"

    #

    # Get a count of files in a directory.

    #

    $directory_file_count = "0"

    $directory_fault_count = "0"

    $Import_directory_pdf = "N:\Import Files"

    $Import_directory_fault = "N:\Fault Files"

    # check that the directory exists.

    $does_directory_exist = (Test-Path $Import_directory_pdf)

    # if it does, then continue

    if ($does_directory_exist)

    {

    # file count does include directories but not a count of their contents.

    $directory_file_count = (get-childitem $Import_directory_pdf -filter *.pdf).count

    $directory_fault_count = (get-childitem $Import_directory_fault -filter *.tif).count

    Write-Host "Directory file count: $directory_file_count"

    Write-Host "Directory fault count: $directory_fault_count"

    }

    else

    {

    # directory doesn't exist

    Write-Host "Directory $server_directory_string - DOES NOT EXIST"

    }

    foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

    $colResults = $objSearcher.FindAll()

    $Connection = New-Object System.Data.SqlClient.SqlConnection("Data Source=mydatabase;Initial Catalog=mydata;Integrated Security=SSPI")

    $Connection.Open()

    $Command = $Connection.CreateCommand()

    #ForEach ($objResult in $colResults)

    #{

    $Count_Import = $directory_file_count

    $Count_Fault = $directory_fault_count

    $Date_Import = get-date

    $Command.CommandText = "INSERT INTO TBL_IMPORT(Count_Import, Count_Fault, Date_Import) Values('$($Count_Import)', '$($Count_Fault)', '$($Date_Import)')"

    $Command.ExecuteNonQuery()

    #}

    $Connection.Close()

    Edited: Today @ 8:31:58 PM by zero1de

  • See Txt.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply