1

Using a PowerShell script in PowerShell 6.x or newer, running on macOS, how do I programmatically determine the version number of macOS?

Edit: Maybe something like this answer, plus string-parsing?: https://stackoverflow.com/a/157784/2134110

Frank Lesniak
  • 560
  • 1
  • 5
  • 18

1 Answers1

1

Easiest way:

sw_vers -productVersion

10.12.6

Or do something with

system_profiler SPSoftwareDataType -xml

like:

[xml]$xml = system_profiler SPSoftwareDataType -xml   
$xml.plist.array.dict.array.dict.string -match 'macos'  

macOS 10.12.6 (16G1510)
js2010
  • 23,033
  • 6
  • 64
  • 66
  • 1
    Nice! Thanks. If you want to amend your answer, this worked well for me: $versionMacOS = [version](sw_vers -productVersion) – Frank Lesniak Apr 28 '20 at 18:51