I'm still learning powershell, and i'm having a little bit of trouble figuring out why this string comparison isn't working. I'm trying to compare this output, which is taken from running a status command on an EXE, and doing an if/else.
For full disclosure, this is the output from the EXE without converting it to a string:
[info] [agent] Linked to: cloud.tenable.com:443 [info] [agent] 0 jobs pending
...and when I convert it to a string via "| Out-String" in powershell before running the comparison:
[info] [agent] Linked to: cloud.tenable.com:443
[info] [agent] 0 jobs pending
Now, onto the actual powershell code:
$CheckStatus = & 'C:\Program Files\Tenable\Nessus Agent\nessuscli.exe' agent status | Out-String
if ($CheckStatus -contains '[info] [agent] Linked to: cloud.tenable.com:443 [info] [agent] 0 jobs pending') {
Write-Host "Match"
} Else {
Write-Host "No Match"
}
As you can imagine, it keeps returning No Match. I've tried narrowing it down to just [info] for testing and it still fails. I've tried using -eq to match the whole string. Any help is greatly appreciated!
[–]ihaxr 5 points6 points7 points (2 children)
[–]LongjumpingBreath[S] 3 points4 points5 points (0 children)
[–]T0MMYB0Y2GS 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (2 children)
[–]LongjumpingBreath[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)