PowerShell Missionary original article. Allowed to be reproduced in 2015-12-15, but must retain the name and provenance, otherwise be held liable
A preface
Judging the operating system version, is an old topic, bat, VBS, there are examples, this is not an important issue, I feel not worth writing posts.
But pinch, with the win version of the increase, PowerShell version fragmentation more and more serious, so "use PowerShell to determine the operating system version"
It's getting more and more important. In other words, you must determine the operating system version before using a slightly biased PowerShell command. Or, strongly
We recommend that you use the latest version of the win server, the win client to play PowerShell.
Advantages and disadvantages of the two methods
Cmd+ver Method:
There seems to be no server or client.
WMI Method:
Recommended
SystemInfo Method:
There is a difference between the command of the Chinese system and the English system.
Three jade flowers on the command
Judging Win7
(Cmd/c ver) [1]-like "*6.1*"
Or
(Systeminfo/fo CSV | convertfrom-csv). ' Os name '-like ' *7* "
PowerShell Missionary original article. Allowed to be reproduced in 2015-12-15, but must retain the name and provenance, otherwise be held liable
English system by:
(Systeminfo/fo CSV | convertfrom-csv). ' Os name '-like ' *7* '
or using the WMI method:
(Get-wmiobject-class Win32_OperatingSystem). Caption-like "*7*"
Judging win8,win8.1
(Cmd/c ver) [1]-like "*6.3*"
Or
(Systeminfo/fo CSV | convertfrom-csv). ' Os name '-like ' *8* "
English system by:
(Systeminfo/fo CSV | convertfrom-csv). ' Os name '-like ' *8* '
or using the WMI method:
(Get-wmiobject-class Win32_OperatingSystem). Caption-like "*8*"
Judging Win10
(Cmd/c ver) [1]-like "*10.*"
Or
(Systeminfo/fo CSV | convertfrom-csv). ' Os name '-like ' *10* "
English system by:
(Systeminfo/fo CSV | convertfrom-csv). ' Os name '-like ' *10* '
or using the WMI method:
(Get-wmiobject-class Win32_OperatingSystem). Caption-like "*10*"
Judging win2012 R2
(Cmd/c ver) [1]-like "*6.3*"
Or
(Systeminfo/fo CSV | convertfrom-csv). ' Os name '-like ' *2012 r2* "
English system by:
(Systeminfo/fo CSV | convertfrom-csv). ' Os name '-like ' *2012 r2* "
or using the WMI method:
(Get-wmiobject-class Win32_OperatingSystem). Caption-like "*2012 r2*"
PowerShell determines the operating system version command