@@ -63,24 +63,24 @@ function Get-AvailableIPSWVersions {
6363 )
6464
6565 if ($IsBeta ) {
66- $command = { mist list firmware " $MacOSCodeNameOrVersion " -- include- betas -- latest -- export " /Applications/export.json" }
66+ $command = { mist list firmware " $MacOSCodeNameOrVersion " -- compatible -- include- betas -- latest -- export " /Applications/export.json" }
6767 } elseif ($IsLatest ) {
68- $command = { mist list firmware " $MacOSCodeNameOrVersion " -- latest -- export " /Applications/export.json" }
68+ $command = { mist list firmware " $MacOSCodeNameOrVersion " -- compatible -- latest -- export " /Applications/export.json" }
6969 } else {
70- $command = { mist list firmware " $MacOSCodeNameOrVersion " -- export " /Applications/export.json" }
70+ $command = { mist list firmware " $MacOSCodeNameOrVersion " -- compatible -- export " /Applications/export.json" }
7171 }
7272
7373 $condition = { $LASTEXITCODE -eq 0 }
7474 Invoke-WithRetry - Command $command - BreakCondition $condition | Out-Null
7575 $softwareList = get-content - Path " /Applications/export.json"
76- $turgetVersion = ($softwareList | ConvertFrom-Json ).version
77- if ($null -eq $turgetVersion ) {
76+ $availableBuilds = ($softwareList | ConvertFrom-Json ).build
77+ if ($null -eq $availableBuilds ) {
7878 Write-Host " Requested macOS '$MacOSCodeNameOrVersion ' version not found in the list of available installers."
7979 $command = { mist list firmware " $ ( $MacOSCodeNameOrVersion.split (' .' )[0 ]) " }
8080 Invoke-WithRetry - Command $command - BreakCondition $condition
8181 exit 1
8282 }
83- return $turgetVersion
83+ return $availableBuilds
8484}
8585
8686function Get-MacOSIPSWInstaller {
@@ -96,21 +96,26 @@ function Get-MacOSIPSWInstaller {
9696 $MacOSName = " macOS Monterey"
9797 } elseif ($MacOSVersion -eq [version ] " 13.0" ) {
9898 $MacOSName = " macOS Ventura"
99+ } elseif ($MacOSVersion -eq [version ] " 14.0" ) {
100+ $MacOSName = " macOS Sonoma"
99101 } else {
100102 $MacOSName = $MacOSVersion.ToString ()
101103 }
102104
103-
104105 Write-Host " `t [*] Finding available full installers"
105106 if ($DownloadLatestVersion -eq $true ) {
106- $targetVersion = Get-AvailableIPSWVersions - IsLatest $true - MacOSCodeNameOrVersion $MacOSName
107- Write-host " `t [*] The 'DownloadLatestVersion' flag is set to true. Latest macOS version is '$MacOSName ' - '$targetVersion ' now "
107+ $targetBuild = Get-AvailableIPSWVersions - IsLatest $true - MacOSCodeNameOrVersion $MacOSName
108+ Write-Host " `t [*] The 'DownloadLatestVersion' flag is set to true. Latest compatible macOS build of '$MacOSName ' is '$targetBuild ' "
108109 } elseif ($BetaSearch -eq $true ) {
109- $targetVersion = Get-AvailableIPSWVersions - IsBeta $true - MacOSCodeNameOrVersion $MacOSName
110- Write-host " `t [*] The 'BetaSearch' flag is set to true. Latestbeta macOS version is '$MacOSName ' - '$targetVersion ' now "
110+ $targetBuild = Get-AvailableIPSWVersions - IsBeta $true - MacOSCodeNameOrVersion $MacOSName
111+ Write-Host " `t [*] The 'BetaSearch' flag is set to true. Latest compatible beta macOS build of '$MacOSName ' is '$targetBuild ' "
111112 } else {
112- $targetVersion = Get-AvailableIPSWVersions - MacOSCodeNameOrVersion $MacOSName - IsLatest $false
113- Write-host " `t [*] The exact version was specified - '$MacOSName ' "
113+ $targetBuild = Get-AvailableIPSWVersions - MacOSCodeNameOrVersion $MacOSName - IsLatest $false
114+ Write-Host " `t [*] Available compatible macOS builds of '$MacOSName ' are: $ ( $targetBuild -join ' , ' ) "
115+ if ($targetBuild.Count -gt 1 ) {
116+ Write-Error " `t [*] Please specify the exact build number of macOS you want to install"
117+ exit 1
118+ }
114119 }
115120
116121 $installerPathPattern = " /Applications/Install ${macOSName} *.ipsw"
@@ -123,12 +128,12 @@ function Get-MacOSIPSWInstaller {
123128 # Download macOS installer
124129 $installerDir = " /Applications/"
125130 $installerName = " Install ${macOSName} .ipsw"
126- Write-Host " `t [*] Requested macOS '$targetVersion ' version installer found, fetching it from mist database"
127- Invoke-WithRetry { mist download firmware " $targetVersion " -- output- directory $installerDir -- firmware- name " $installerName " } {$LASTEXITCODE -eq 0 } | Out-Null
131+ Write-Host " `t [*] Requested macOS '$targetBuild ' version installer found, fetching it from mist database"
132+ Invoke-WithRetry { mist download firmware " $targetBuild " -- output- directory $installerDir -- firmware- name " $installerName " } { $LASTEXITCODE -eq 0 } | Out-Null
128133 if (Test-Path " $installerDir$installerName " ) {
129134 $result = " $installerDir$installerName "
130135 } else {
131- Write-host " `t [*] Requested macOS '$targetVersion ' version installer failed to download"
136+ Write-Error " `t [*] Requested macOS '$targetBuild ' version installer failed to download"
132137 exit 1
133138 }
134139 return $result
@@ -169,7 +174,7 @@ function Get-MacOSInstaller {
169174 exit 1
170175 }
171176 Show-StringWithFormat $filteredVersions
172- $osVersions = $filteredVersions.OSVersion | Sort-Object {[version ]$_ }
177+ $osVersions = $filteredVersions.OSVersion | Sort-Object { [version ]$_ }
173178 $MacOSVersion = $osVersions | Select-Object - Last 1
174179 Write-Host " `t [*] The 'DownloadLatestVersion' flag is set. Latest macOS version is '$MacOSVersion ' now"
175180 }
@@ -248,15 +253,15 @@ function Install-SoftwareUpdate {
248253 $command = " sw_vers"
249254 $guestMacosVersion = Invoke-SSHPassCommand - HostName $HostName - Command $command
250255 if ($guestMacosVersion [1 ] -match " 12" ) {
251- foreach ($update in $listOfUpdates ){
256+ foreach ($update in $listOfUpdates ) {
252257 # Filtering updates that contain "Ventura" word
253258 if ($update -notmatch " Ventura" ) {
254259 $command = " sudo /usr/sbin/softwareupdate --restart --verbose --install '$ ( $update.trim ()) '"
255260 Invoke-SSHPassCommand - HostName $HostName - Command $command
256261 }
257262 }
258263 } elseif ($guestMacosVersion [1 ] -match " 13" ) {
259- foreach ($update in $listOfUpdates ){
264+ foreach ($update in $listOfUpdates ) {
260265 # Filtering updates that contain "Sonoma" word
261266 if ($update -notmatch " Sonoma" ) {
262267 $command = " sudo /usr/sbin/softwareupdate --restart --verbose --install '$ ( $update.trim ()) '"
@@ -302,7 +307,11 @@ function Invoke-SSHPassCommand {
302307 " ${env: SSHUSER} @${HostName} "
303308 )
304309 $sshPassOptions = $sshArg -join " "
305- $result = bash - c " $sshPassOptions \"" $Command \"" 2>&1"
310+ if ($PSVersionTable.PSVersion.Major -eq 7 -and $PSVersionTable.PSVersion.Minor -le 2 ) {
311+ $result = bash - c " $sshPassOptions \"" $Command \"" 2>&1"
312+ } else {
313+ $result = bash - c " $sshPassOptions `" $Command `" 2>&1"
314+ }
306315 if ($LASTEXITCODE -ne 0 ) {
307316 Write-Error " There is an error during command execution:`n $result "
308317 exit 1
0 commit comments