Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Count imported Files Expand / Collapse
Author
Message
Posted Saturday, June 29, 2013 11:41 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 13, 2014 5:05 AM
Points: 6, Visits: 52
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
Post #1468812
Posted Saturday, June 29, 2013 1:21 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 13, 2014 5:05 AM
Points: 6, Visits: 52
See Txt.
Post #1468820
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse