Matthew Goode
Matthew Goode

Reputation: 105

powershell if statements strange behavior

So here's a kind of a silly problem. Can someone explain how this makes sense? I don't really know what else to ask. Why would the if statement change the value of the variable in it?

PS C:\Users\HD2> $format = 6

PS C:\Users\HD2> $format
6

PS C:\Users\HD2> if($format = 1){write-host "woo"}
woo

PS C:\Users\HD2> $format
1

Upvotes: 2

Views: 293

Answers (1)

John Hubert
John Hubert

Reputation: 2214

In powershell, the = operator is used to assign values to a variable. To do comparison, use the -eq operator.

Upvotes: 5

Related Questions