I need to check if 2 variable values ​​are the same.

I have a script that asks for login ($ user) and password ($ password). Based on this, it executes a sql query with the result being a password ($ result)

$query = "select haslo from uzytkownicy where login='$user'"

$result = Get-ODBC-Data -query $query

if ($password -eq $result){

Write-Output "ok" }

else {

Write-Output "nok"


My problem is that even if $ password is the same as $ result, I have a nok. I suppose the problem is that the result of the query is

(write-output $ result)



( write-output $password )


so there are 2 additional lines above the password. Can anyone tell me what I’m doing wrong?

Please use the pre tags to format your code and use $result.haslo instead of $result

It works. Thx.

sharing the problem and solution for others.

$password is a string and $result is an object, hence the comparison fails. when doing it like this below is what actually happens.

since $Password is a string, then the $result will be converted to string(internally) to do a comparison and will result in to @{haslo

So, solution is to cherrypick the value like $result.haslo,

if($password -ew $result.haslo)
# whatever