# If I run the following:
$lQuery = # (See: Notes Area)
$locations = Inovke-MySqlQuery $lQuery
# I get:
Client Location
------ --------
[Client01] [Location01]
[Client02] [Location02]
[Client03] [Location03]
(etc.)
# So, then, if $client and $location are the supplied parameters
# (being pulled from the returned list above of 63 items), and I do the following
# (which, notice the calling of $var variable is outside the IF/ELSE):
$cSearch = '*' + "$client" + '*'
$lSearch = '*' + "$location" + '*'
$tmpTable = '`' + $client + "_" + $location + '`'
$query = # (See: Notes Area)
ForEach ($l in $locations) {
$var = If ($l.Client -like "*[Client62]*" -And $l.Location -like "*[Location62]*") {
'Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch)}'
}
Else {
'Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch) -And (!($_.download -gt "100" -or $_.upload -gt "100"))}'
}
}
$var
}
# I get:
Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch) -And (!($_.download -gt "100" -or $_.upload -gt "100"))}
Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch) -And (!($_.download -gt "100" -or $_.upload -gt "100"))}
Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch) -And (!($_.download -gt "100" -or $_.upload -gt "100"))}
...
Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch)}
Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch) -And (!($_.download -gt "100" -or $_.upload -gt "100"))}
Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch) -And (!($_.download -gt "100" -or $_.upload -gt "100"))}
# P much, everyone seems to be getting the right variable. Perfect.
# BUT, when I change my script to include it (link to original script in Notes),
# [At Line 13] Like so (in actual script, this is all one line, but I expanded
# it for easier reading:
...
$dataSet = If ($client -like "*[Client62]*" -And $location -like "*[Location62]*") {
Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch)}
}
Else {
Invoke-MySqlQuery $query | Where {($_.client -like $cSearch) -And ($_.location -like $lSearch) -And (!($_.download -gt "100" -or $_.upload -gt "100"))}
}
...
# It returns errors:
Cannot index into a null array.
At line:23 char:17
+ $title = "$($dataSet[0].client)" + " (" + "$($dataSet[0].location)" + ")"
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
At line:23 char:50
+ $title = "$($dataSet[0].client)" + " (" + "$($dataSet[0].location)" + ")"
+ ... ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Link to Original Scripthttps://codeclippet.com/KW5CxqN3x4aTQ$lQuerySELECT DISTINCT `clients`.`Name` AS 'Client', `locations`.`Name` AS 'Location'FROM `plugin_speedtest_enabled`LEFT JOIN `computers` ON `plugin_speedtest_enabled`.`computerid` = `computers`.`ComputerID`LEFT JOIN `clients` ON `computers`.`ClientID` = `clients`.`ClientID`LEFT JOIN `locations` ON `computers`.`LocationID` = `locations`.`LocationID`
$queryCREATE TEMPORARY TABLE IF NOT EXISTS $tmpTable ( `date` DATE NULL, `download` DECIMAL(10,2) NULL, `upload` DECIMAL(10,2) NULL, `ping` DECIMAL (10,2) NULL, `client` TEXT NULL, `location` TEXT NULL)COLLATE='utf8_general_ci'ENGINE=InnoDB;
INSERT INTO $tmpTable ( `date`, `download`, `upload`, `ping`, `client`, `location`)
SELECT CAST(`plugin_speedtest`.`date` AS char), ROUND(`plugin_speedtest`.`download` / 1024,2), ROUND(`plugin_speedtest`.`upload` / 1024,2), `plugin_speedtest`.`ping`, `clients`.`Name` AS 'Client', `locations`.`Name` AS 'Location'FROM `plugin_speedtest`LEFT JOIN `computers` ON `plugin_speedtest`.`computerid` = `computers`.`ComputerID`LEFT JOIN `clients` ON `computers`.`ClientID` = `clients`.`ClientID`LEFT JOIN `locations` ON `computers`.`LocationID` = `locations`.`LocationID`;
SELECT `date`, `download`, `upload`, `ping`, `client`, `location`FROM $tmpTable;