As an admin, you may need to look up a list of previously installed software updates for a device. You can do this pretty easily with system_profiler
and the SPInstallHistoryDataType
command.
/usr/sbin/system_profiler SPInstallHistoryDataType
This will spit out a complete list of updates installed on the device and their source and installation date, sorted by date.
Slack: Version: 4.25.0 Source: 3rd Party Install Date: 3/29/22, 8:12 AM Apple Configurator: Version: 2.15.1 Source: Apple Install Date: 3/29/22, 12:03 PM Keynote: Version: 12.0 Source: Apple Install Date: 4/7/22, 8:41 AM macOS 12.3.1: Version: 12.3.1 Source: Apple Install Date: 4/10/22, 12:22 PM
This is useful, but let’s say I want to only show macOS update history. In fact, I want to precisely determine, “Has this device updated to macOS Ventura from a previous version of macOS?”. If not, then it likely came preinstalled with macOS Ventura or has been wiped and restored with macOS Ventura.
So let’s dive in and figure out how we can accomplish our end goal…
I’m going to grep that list of updates for only those lines containing “macOS” and strip any lines that contain “macOS 13.*” (remember, I’m trying to determine if the device installed any updates prior to macOS Ventura).
/usr/sbin/system_profiler SPInstallHistoryDataType | grep "macOS" | grep -v "macOS 13\.*"
If the device has installed multiple macOS updates over the months/years, your output will look something like this:
macOS 12.0.1: Setup macOS Recovery Dependencies: macOS 12.0.1: macOS 12.1: macOS 12.2.1: macOS 12.3.1: macOS 12.4: macOS 12.5: macOS 12.5.1: macOS 12.6: macOS 12.6.1: macOS Ventura:
As a quick side note: If you’d like install date information for all your macOS updates, you can modify the grep command to include those details.
/usr/sbin/system_profiler SPInstallHistoryDataType | grep -A5 "macOS"
-- macOS 12.6: Version: 12.6 Source: Apple Install Date: 9/24/22, 11:06 AM -- macOS 12.6.1: Version: 12.6.1 Source: Apple Install Date: 10/28/22, 4:29 PM -- macOS Ventura: Version: 13.0.1 Source: Apple Install Date: 12/18/22, 12:09 AM -- macOS 13.0.1: Version: 13.0.1 Source: Apple Install Date: 12/18/22, 10:40 PM -- macOS 13.1: Version: 13.1 Source: Apple Install Date: 12/29/22, 3:10 PM -- macOS 13.2.1: Version: 13.2.1 Source: Apple Install Date: 2/13/23, 6:07 P
So we’ve got our install history. Now we need to check if that output contains any previous versions of macOS. If so, I know this device upgraded from an older version of macOS to macOS Ventura. If not, the device likely came pre-installed with macOS Ventura or was wiped and restored with it. In the example below, I’ll exit 1
on devices that have upgraded from an older version of macOS so I can be alerted in my MDM.
#!/bin/zsh osVer="$(sw_vers -productVersion)" previousmacOS=$(/usr/sbin/system_profiler SPInstallHistoryDataType | grep "macOS" | grep -v "macOS 13\.*") if [[ $osVer > 13.* && $previousmacOS =~ "macOS (10|11|12)\.*" ]]; then echo "Device upgraded to macOS Ventura from a previous version of macOS" exit 1 else echo "No macOS installs detected before macOS Ventura" exit 0 fi
Alternative: Use softwareupdate –history
While SPInstallHistoryType extracts data from the system install history (including updates installed from the App Store, system software updates, and other package installations), in this particular blog post we’re really only focusing on macOS updates in our example.
In that case, the softwareupdate
binary has a --history
flag we can leverage to show a history of updates that were managed through Apple’s softwareupdate
utility, which primarily focuses on macOS updates and patches.
Let’s look at that command and its resulting output
% /usr/sbin/softwareupdate --history
Display Name Version Date ------------ ------- ---- macOS Ventura 13.5.1 13.5.1 08/21/2023, 09:01:12 macOS Ventura 13.5.2 13.5.2 09/08/2023, 12:56:52 Pro Video Formats 2.2.7 09/23/2023, 14:04:35 Pro Video Formats 2.2.7 09/23/2023, 14:04:40 macOS Ventura 13.6 13.6 09/23/2023, 14:06:18 macOS Sonoma 14.0 14.0 09/28/2023, 15:53:37
If we want to only focus on getting a list of macOS updates, we can grep those out.
% /usr/sbin/softwareupdate --history | grep "macOS" macOS Ventura 13.5.1 13.5.1 08/21/2023, 09:01:12 macOS Ventura 13.5.2 13.5.2 09/08/2023, 12:56:52 macOS Ventura 13.6 13.6 09/23/2023, 14:06:18 macOS Sonoma 14.0 14.0 09/28/2023, 15:53:37
Who knows when this might come in handy, but I hope you find it useful!
Happy adminning!