Frank Lesniak
Frank Lesniak

Reputation: 630

How do I Determine the Current Version of macOS Using PowerShell 6.x or Newer?

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

Upvotes: 1

Views: 295

Answers (1)

js2010
js2010

Reputation: 27473

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)

Upvotes: 1

Related Questions