0

I am working with windows 7 and 8.1 machines. I would like to implement a PowerShell script to detect the OS and install a program based on the result.

So far I can get the OS but I get caught in the IF statement.

$Win7="6.1.7601" $Win8="Not tested yet" $Version=(Get-WmiObject win32_operatingsystem).version write-host Your windows version is $version. if(!($version="6.1.7601")) {skip} else {Install file} 

I am trying to skip this script and return to a main script if the OS is not win7 otherwise it should install the files needed. Any help would be much appreciated.

1
  • 2
    Do you mean -eq there? Commented Apr 29, 2015 at 15:56

1 Answer 1

1

The = operator is used to set the value of something. You need to use the -eq operator, which compares objects.

if(!($version -eq "6.1.7601"))

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for that. Things run much smoother now
I'd recommend using -ne instead of !(-eq).
I'd recommend excluding build number from comparison. I.e. check that version starts with 6.1 only.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.