Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

correct if statement to specify executing on the basis of operating system version

$
0
0

hi Guys

i am creating a general PS script which i want to execute it on my network systems.

this is a general script & i don't want to create separate script for each of the following Operating systems.

in my script, some commands are related to windows 2012 which definitely can't be applied on client OS (like win 7 or win 8) & vice versa. 

so within my script, in different places, i need to use multiple if conditional statement, for example:

if OS is windows 7, command 1 be executed

if OS is windows 2008, command 2 be executed

if OS is windows 8, command 3 be executed

and finally if OS is windows 2012, command 4 be executed.

i now that via Get-WmiObject -class win32_operatingsystem version, we can find OS version & also i found this in microsoft:

Operating system Version number
Windows 8.1                     6.3*
Windows Server 2012 R2  6.3*
Windows 8                        6.2
Windows Server 2012       6.2
Windows 7                        6.1
Windows Server 2008 R2  6.1
Windows Server 2008       6.0

but i don't know how to use these stuff together to create correct if statements.

may anyone give me a correct example please?

thanks in advanced


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>