Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Count imported Files


Count imported Files

Author
Message
zero1de
zero1de
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 99
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
zero1de
zero1de
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 99
See Txt.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search