-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCompare ESET and LabTech Machines by array.ps1
More file actions
101 lines (88 loc) · 7.24 KB
/
Copy pathCompare ESET and LabTech Machines by array.ps1
File metadata and controls
101 lines (88 loc) · 7.24 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# The Run-MySQLQuery function sets up the connection so that we can reach out to both MySQL databases.
Function Run-MySQLQuery {
Param(
[Parameter(
Mandatory = $true,
ParameterSetName = '',
ValueFromPipeline = $true)]
[string]$query,
[Parameter(
Mandatory = $true,
ParameterSetName = '',
ValueFromPipeline = $true)]
[string]$connectionString
)
Begin {
Write-Verbose "Starting Begin Section"
}
Process {
Write-Verbose "Starting Process Section"
try {
# load MySQL driver and create connection
Write-Verbose "Create Database Connection"
# You could also could use a direct Link to the DLL File
# $mySQLDataDLL = "C:\scripts\mysql\MySQL.Data.dll"
# [void][system.reflection.Assembly]::LoadFrom($mySQLDataDLL)
[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection
$connection.ConnectionString = $ConnectionString
Write-Verbose "Open Database Connection"
$connection.Open()
# Run MySQL Querys
Write-Verbose "Run MySQL Querys"
$command = New-Object MySql.Data.MySqlClient.MySqlCommand($query, $connection)
$dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command)
$dataSet = New-Object System.Data.DataSet
$recordCount = $dataAdapter.Fill($dataSet, "data")
$dataSet.Tables["data"]
}
catch {
Write-Host "Could not run MySQL Query" $Error[0]
}
Finally {
Write-Verbose "Close Connection"
$connection.Close()
}
}
End {
Write-Verbose "Starting End Section"
}
}
#The Two Lines Below establish the connections, get the results from the query, and assign them to the two variables.
$EsetComputers = run-MySQLQuery -ConnectionString "Server=localhost;Uid=root;Pwd=mekukiggellitoka;database=ESETRADB;Allow Zero Datetime=true;" "SELECT ComputerName as Name,macaddress AS Mac,clientdomain AS Domain FROM CLIENT"
$LabTechComputers = run-MySQLQuery -ConnectionString "Server=localhost;Uid=root;Pwd=mekukiggellitoka;database=LABTECH;Allow Zero Datetime=true;" "SELECT name,REPLACE(mac,'-','') AS Mac,REPLACE(Domain,'DC:','') AS Domain FROM computers"
#Below the variables are set for all of the arrays and the computations done around the arrays.
$MaxArrCount = ($EsetComputers | Measure-Object).Count-1;
$MissingEntries=@();
$EsetArray = @()
$LabTechArray = @()
$LTUBOUND = $LabTechComputers.GetUpperBound(0);
#Below is the looping functionality to do the array comparison.
[int]$i = 0;
while($i -lt $MaxArrCount)
{
[int]$t = 0;
$found = $false;
$curName = $EsetComputers[$i][0].ToUpper();
$curMac = $EsetComputers[$i][1].ToUpper();
$curDomain = $EsetComputers[$i][2].ToUpper();
while($t -lt $LTUbound)
{
$LTCurName = $LabTechComputers[$t][0].ToUpper();
$LTCurMac = $LabTechComputers[$t][1].ToUpper();
$LTCurDomain = $LabTechComputers[$t][2].ToUpper();
if($curName -eq $LTCurName <#-and $curMac -eq $LTCurMac#> -and $curDomain -eq $LTCurDomain)
{
#Matches!
$found = $true;
break;
}
$t+=1;
}
if($found -ne $true)
{
$MissingEntries+=@(($curName,$curDomain))
}
$i+=1;
}
Out-File -InputObject $MissingEntries -FilePath 'D:\LTShare\Transfer\Scripts\ESET\missingagents.txt'