Reputation: 630
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
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