-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOBDEASQL.ps1
More file actions
executable file
·74 lines (55 loc) · 2.06 KB
/
COBDEASQL.ps1
File metadata and controls
executable file
·74 lines (55 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
cls
$LOGfile = "C:\test\DEA Images3.bdf"
Function LogWrite
{
Param ([string]$logstring)
Add-content $LOGfile -value $logstring
}
$pattern = "^(.*)_(\d{8}).tif$"
## Connect to the SQL server and the Database
$conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=Gemini-ps1; Initial Catalog=COBDEA; Integrated Security=SSPI; MultipleActiveResultSets=true")
## Open DB Connection
$conn.Open()
$startingLocation = "X:\Dev_3 Tifs"
$files = gci -path $startingLocation -recurse -Include "*.tif"
foreach($file in $files){
# Write-Host $file.Name
if($file.Name -match $pattern){
# Write-Host $Matches[1]
$temp = $Matches[1]
$temp = $temp -replace "\'", "''"
$sqlText = "SELECT EmpID, [First Name], [Middle N# or I#], [Last Name], [Document Type], [Transaction Type]
FROM [COBDEA].[dbo].[Sheet1$]
WHERE [Original File Name] LIKE '$temp%'"
$cmd = new-object System.Data.SqlClient.SqlCommand($sqlText, $conn);
$reader = $cmd.ExecuteReader()
$results = @()
$temp = ""
while ($reader.Read())
{
$row = @{}
for ($i = 0; $i -lt $reader.FieldCount; $i++)
{
$row[$reader.GetName($i)] = $reader.GetValue($i)#used to generate a results file below that is commented out
$results += $reader.GetValue($i)
$temp += $reader.GetValue($i)
$temp += "|"
}
}
write-host $results
if($Matches[2] -eq '00010001'){
$temp2 = "x:\"
$temp2 += $Matches[0]
$temp2 += "|"
$temp = $temp2 + $temp
LogWrite -logstring $temp
#Write-Host 'ea'
}else{
$temp = "x:\"
$temp += $Matches[0]
$temp += "|"
LogWrite $temp
}
}
}
$conn.Close()