So I have some code I wrote to take the input form a text file and run some sql checks against another database I populated:
$volOutput = gc C:\Users\<user>\Desktop\mutant.txt
foreach ($m in $volOutput) {
$check = $m.split()[-1] | select -Unique
foreach ($c in $check) {
#$c - this lists all of them so the foreach is working...
# Build the connection and search the db for $c names.
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=(localdb)\mutex; Database=MutexObjects"
$conn.Open()
$db = $conn.CreateCommand()
$db.CommandText = "select Names from Objects WHERE Names='$c'"
$db.ExecuteScalar()
$conn.Close()
} # Foreach Check
} # First foreach
The return values I get are:
PS C:\> B:\Programming\powershell\parse_vol.ps1
ZonesCounterMutex
ZoneAttributeCacheCounterMutex
ZonesCacheCounterMutex
ZoneAttributeCacheCounterMutex
ZonesLockedCacheCounterMutex
ZonesCounterMutex
ZoneAttributeCacheCounterMutex
ZonesCacheCounterMutex
ZoneAttributeCacheCounterMutex
ZonesLockedCacheCounterMutex
Which is correct, but it's also missing a lot more. If I take individual samples and run queries from within SQL management studio for example, I get:
I populated the word "test" in each list as a....test.
Select Names From Objects WHERE Names='test'
Names
test
But I don't see test on the output from the above code. There are about 5 or 6 more than it's missing that I have validated manually by querying the db w/in SQL management studio.
Any help is much appreciated.