I am trying to get info about an iSCSI-Targets Connectionstate.
Ideally I want to have a variable with a value that is True or False for connected or not connected, so that i can run commands to connect or disconnect as needed.
If i set the Variable directly it's working fine. Setting the Variable with the output of a cmdlet seems to work but comparing the Values False or True with IF is always resulting in True. For me the question is: where is the difference between setting the Variable directly to True and using the output of the cmdlet...?
Sample one:
$IsConnected=true
if($IsConnected -eq 'true') {
echo IsConnected!
} else {
echo IsNotConnected
}
Results, as expected, in: IsConnected
Sample two:
$IsConnected=False
if($IsConnected -eq 'true') {
echo IsConnected!
} else {
echo IsNotConnected
}
Results, as expected, in: IsNotConnected
So now my knowledge ends...:
Sample three:
PS ~> $IsConnected=get-iscsitarget | select -ExpandProperty IsConnected
PS ~> echo $IsConnected
True
PS ~> if($IsConnected -eq 'True') {Echo "IsConnected"}else{echo "IsNotConnected"}
IsConnected
PS ~> if($IsConnected -eq 'False') {Echo "IsConnected"}else{echo "IsNotConnected"}
IsConnected
PS ~> if($IsConnected -eq '17beerarenotenaugh') {Echo "IsConnected"}else{echo "IsNotConnected"}
IsConnected