dimanche 23 mai 2021

Ifelse statement not working. Always defaults to the same condition

I've done these so many times, but for some reason it seems to be only using the first condition and ignoring the rest.

Code:

$input = set-content -path ".\module.txt" -value 'Colors'
$output = get-content -path ".\module.txt"
    
    if ($output -ne ''){
        if ($output = 'Words'){set-content -path ".\module.txt" -value 'Numbers'}
            elseif ($output = 'Colors'){set-content -path ".\module.txt" -value 'Sounds'}
                else{write-host 'Somethings missing'}
                    }

No matter what I put in the $input variable, it will always complete the first if statement and change the text file content to read Numbers

So it can definitely update the content in the file, but it ignores the elseif and even the else statements.

Can anyone spot what I've done wrong here? Thanks

Aucun commentaire:

Enregistrer un commentaire