Code Monkey home page Code Monkey logo

Comments (12)

timsutton avatar timsutton commented on July 19, 2024 2

Can you provide the output of your brigadier command? Brigadier will fetch the newest-posted package available for the Mac model on which it's running, and there are some additional options which can direct it to download ESDs for different models.

from brigadier.

nathanmcnulty avatar nathanmcnulty commented on July 19, 2024 2

As promised, here's the Powershell script I've written based on Tim's amazing work. I actually wrote this converting python over, and have since written our own internal version that lacks many of the features such as passing parameters and specifying to keep files, etc. I have tried to keep this version up to date with fixes and additions I've done in my other script, so if anything isn't working properly, let me know. This is basically what we use with some of the features of Brigadier added back in.

Edit: Note that we only support 64bit OS installs (exclusively Windows 10 now), so I have not tested (and don't believe this will work with) 32bit OS installs.

[CmdletBinding()]
Param(
    [string]$Model = (Get-WmiObject -Class Win32_ComputerSystem).Model,
    [switch]$Install,
    [string]$OutputDir = "$env:TEMP",
    [switch]$KeepFiles,
    [array]$ProductId,
    [string]$SUCATALOG_URL = 'http://swscan.apple.com/content/catalogs/others/index-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog',
    [string]$SEVENZIP_URL = 'http://www.7-zip.org/a/7z1604-x64.msi'
)

# Disable Invoke-WebRequest progress bar to speed up download due to bug
$ProgressPreference = "SilentlyContinue"

# Create Output Directory if it does not exist
if (!(Test-Path $OutputDir)) { New-Item -Path $OutputDir -ItemType Directory -Force }

# Check if at least 7zip 15.14 is installed. If not, download and install it.
$7z = "$env:ProgramFiles\7-Zip\7z.exe"
if (Test-Path $7z) { $7zInstalled = $true }
if ([decimal](Get-ItemProperty $7z).VersionInfo.FileVersion -lt 15.14) {
    Invoke-WebRequest -Uri $SEVENZIP_URL -OutFile "$OutputDir\$($SEVENZIP_URL.Split('/')[-1])" -ErrorAction Stop
    Start-Process -FilePath $env:SystemRoot\System32\msiexec.exe -ArgumentList "/i $OutputDir\$($SEVENZIP_URL.Split('/')[-1]) /qb- /norestart" -Wait -Verbose
}

# Read data from sucatalog and find all Bootcamp ESD's
[xml]$sucatalog = Invoke-WebRequest -Uri $SUCATALOG_URL -Method Get -ErrorAction Stop
$sucatalog.plist.dict.dict.dict | Where-Object { $_.String -match "Bootcamp" } | ForEach-Object {
    # Search dist files to find supported models, using regex match to find models in dist files - stole regex from brigadier's source
    $SupportedModels = [regex]::Matches((Invoke-RestMethod -Uri ($_.dict | Where-Object { $_.Key -match "English" }).String).InnerXml,"([a-zA-Z]{4,12}[1-9]{1,2}\,[1-6])").Value
    if ($SupportedModels -contains $Model) { 
        $version = [regex]::Match(($_.dict | Where-Object { $_.Key -match "English" }).String,"(\d{3}-\d{5})").Value
        Write-Output "Found supported ESD: $Version"
        [array]$bootcamplist += $_ 
    }
}
if ($bootcamplist.Length -gt 1) { 
    Write-warning "Found more than 1 supported Bootcamp ESD. Selecting newest based on posted date which may not always be correct"
    $bootcamplist | ForEach-Object { 
        if ($_.date -gt $latestdate) { 
            $latestdate = $_.date
            $download = $_.array.dict.string | Where-Object { $_ -match '.pkg' }
        }
    }
} else { $download = $bootcamplist.array.dict.string | Where-Object { $_ -match '.pkg' }}

# Download the BootCamp ESD
Invoke-WebRequest -Uri $download -Method Get -OutFile "$OutputDir\BootCampESD.pkg" -UseBasicParsing -ErrorAction Stop
if (Test-Path -Path "$OutputDir\BootCampESD.pkg") {
    # Extract the bootcamp installer
    Invoke-Command -ScriptBlock { 
        & $7z -o"$OutputDir" -y e "$OutputDir\BootCampESD.pkg"
        & $7z -o"$OutputDir" -y e "$OutputDir\Payload~"
        # If just downloading, put the extracted installers on the desktop
        if ($Install) { 
		& $7z -o"$OutputDir" -y x "$OutputDir\WindowsSupport.dmg" 
	} else { 
		if ($OutputDir -eq "$env:TEMP") { & $7z -o"$env:USERPROFILE\Desktop\$version" -y x "$OutputDir\WindowsSupport.dmg" } else { & $7z -o"$OutputDir" -y x "$OutputDir\WindowsSupport.dmg" }
	}
    }
} else { Write-Warning "BootCampESD.pkg could not be found"; exit } 

# Uninstall 7zip if we installed it
if ($7zInstalled -ne $true) { Start-Process -FilePath $env:SystemRoot\System32\msiexec.exe -ArgumentList "/x $OutputDir\$($SEVENZIP_URL.Split('/')[-1]) /qb- /norestart" -Wait }

# Install Bootcamp and use MST if specified (I uploaded one that I had to use to fix the latest ESD on an iMac14,1)
if ($Install) { 
	# Install Bootcamp
	$scaction=New-ScheduledTaskAction -Execute "msiexec.exe" -Argument "/i $OutputDir\Bootcamp\Drivers\Apple\BootCamp.msi /qn /norestart"
	$sctrigger=New-ScheduledTaskTrigger -At ((Get-Date).AddSeconds(15)) -Once
	$scprincipal=New-ScheduledTaskPrincipal "SYSTEM" -RunLevel Highest
	$scsettings=New-ScheduledTaskSettingsSet
	$sctask=New-ScheduledTask -Action $scaction -Principal $scprincipal -Trigger $sctrigger -Settings $scsettings
	Register-ScheduledTask "Install Bootcamp" -InputObject $sctask -User "SYSTEM"
	do { Write-Output "Sleeping 20 seconds"; Start-Sleep -Seconds 20 } while (Get-Process -Name "msiexec" -ErrorAction SilentlyContinue)
} else { exit }

# Clean up
if ($KeepFiles) { exit } else { Remove-Item -Path "$OutputDir\*" -Recurse -Force -ErrorAction SilentlyContinue }

from brigadier.

aruizca avatar aruizca commented on July 19, 2024 1
C:\Users\Antonio\Downloads>brigadier.exe -k
Using Mac model: MacBookPro12,1.

Model supported in package distribution file at http://swcdn.apple.com/content/downloads/39/14/031-55710/u2c6bi4yl91ud1lqc3k53bx9860hvsnf7z/031-55710.English.dist.

Distribution 031-55710 supports the following models: MacBook8,1, MacBookAir5,1, MacBookAir5,2, MacBookAir6,1, MacBookAir6,2, MacBookAir7,1, MacBookAir7,2, MacBookPro9,1, MacBookPro9,2, MacBookPro11,1, MacBookPro11,2, MacBookPro11,3, MacBookPro11,4, MacBookPro11,5, MacBookPro12,1, MacPro6,1, Macmini6,1, Macmini6,2, Macmini7,1, iMac13,1, iMac13,2, iMac13,3, iMac14,1, iMac14,2, iMac14,3, iMac14,4, iMac15,1.

Making directory C:\Users\Antonio\Downloads\BootCamp-031-55710..

Fetching Boot Camp product at URL http://swcdn.apple.com/content/downloads/39/14/031-55710/u2c6bi4yl91ud1lqc3k53bx9860hvsnf7z/BootCampESD.pkg.

100.0% 1614454784 / 1614454648 bytes
Extracting...

Calling 7-Zip command: C:\Program Files\7-Zip\7z.exe e -oc:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife -y c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\BootCampESD.pkg


7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04

Scanning the drive for archives:
1 file, 1614454648 bytes (1540 MiB)

Extracting archive: c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\BootCampESD.pkg
--
Path = c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\BootCampESD.pkg
Type = Xar
Physical Size = 1614454648
SubType = pkg
Headers Size = 3180
----
Path = Payload
Size = 1614449168
Packed Size = 1614449168
Modified = 2016-03-31 22:21:12
Created = 2016-03-31 22:21:32
Accessed = 2016-03-31 22:15:12
Mode = -rw-r--r--
User = root
Group = wheel
Method = octet-stream
--
Path = Payload
Type = bzip2

Everything is Ok

Size:       1613847552
Compressed: 1614454648
Calling 7-Zip command: C:\Program Files\7-Zip\7z.exe e -oc:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife -y c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\Payload~


7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04

Scanning the drive for archives:
1 file, 1613847552 bytes (1540 MiB)

Extracting archive: c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\Payload~
--
Path = c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\Payload~
Type = Cpio
Physical Size = 1613847552
SubType = Portable ASCII

Everything is Ok

Folders: 4
Files: 1
Size:       1613846904
Compressed: 1613847552
Calling 7-Zip command: C:\Program Files\7-Zip\7z.exe x -oC:\Users\Antonio\Downloads\BootCamp-031-55710 -y c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\WindowsSupport.dmg


7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04

Scanning the drive for archives:
1 file, 1613846904 bytes (1540 MiB)

Extracting archive: c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\WindowsSupport.dmg
--
Path = c:\users\antonio\appdata\local\temp\bootcamp-unpack_nevife\WindowsSupport.dmg
Type = Dmg
Physical Size = 1613846904
Method = Copy ZLIB CRC
Blocks = 10602
----
Path = 0.Apple_ISO
Size = 2779248640
Packed Size = 1613213990
CRC = AFCB68E6
Comment = BOOTCAMP (Apple_ISO : 0)
Method = Copy ZLIB CRC
--
Path = 0.Apple_ISO
Type = Iso
Physical Size = 2779248640
Created = 2016-03-31 22:07:10
Modified = 2016-03-31 22:07:10

Everything is Ok

from brigadier.

timsutton avatar timsutton commented on July 19, 2024 1

Moreover, is there a source documenting the differences between Boot Camp 6.0.x and 6.1? On my iMac17,1 (the 2015 Retina 5K) it downloaded 6.0.6251. We've been deploying Windows 10 64-bit on 2013-2015 iMacs (both retina and non-retina) using Brigadier, so whatever variants of 6.0.x are being pulled do fully support Windows 10.

from brigadier.

aruizca avatar aruizca commented on July 19, 2024 1

from brigadier.

timsutton avatar timsutton commented on July 19, 2024 1

What happens if you use the Apple Bootcamp Assistant to build an installer disc and install the drivers from that? (I'd just be curious to know whether Apple's tool downloads the same drivers, and if it does, then if there's any difference in how we're installing them via msiexec /i vs. running Apple's setup.exe wrapper)

from brigadier.

aruizca avatar aruizca commented on July 19, 2024 1

from brigadier.

nathanmcnulty avatar nathanmcnulty commented on July 19, 2024 1

I keep meaning to get my Powershell script uploaded here at some point, but I have found that installing Bootcamp via msiexec or setup.exe does not install correctly most of the time unless it is run with the SYSTEM account (which is what the installer is expecting because it is usually kicked off by the unattend that Bootcamp Assistant uses). The only in-box solution to do this is through Task Scheduler, but you could alternatively download psexec.exe and use that if you'd like.

Here's the PS snippet I'm using to register and run a scheduled task to handle the install, and I'll see if I can add enough comments and clean up my code enough to share the full Powershell script we use to install Bootcamp on the Windows side.

# Install Bootcamp
$scaction=New-ScheduledTaskAction -Execute "msiexec.exe" -Argument "/i $OutputDir\Bootcamp\Drivers\Apple\BootCamp.msi /qn /norestart"
$sctrigger=New-ScheduledTaskTrigger -At ((Get-Date).AddSeconds(15)) -Once
$scprincipal=New-ScheduledTaskPrincipal "SYSTEM" -RunLevel Highest
$scsettings=New-ScheduledTaskSettingsSet
$sctask=New-ScheduledTask -Action $scaction -Principal $scprincipal -Trigger $sctrigger -Settings $scsettings
Register-ScheduledTask "Install Bootcamp" -InputObject $sctask -User "SYSTEM"
do { Write-Output "Sleeping 20 seconds"; Start-Sleep -Seconds 20 } while (Get-Process -Name "msiexec" -ErrorAction SilentlyContinue)

from brigadier.

timsutton avatar timsutton commented on July 19, 2024 1

I keep meaning to get my Powershell script uploaded here at some point, but I have found that installing Bootcamp via msiexec or setup.exe does not install correctly most of the time unless it is run with the SYSTEM account (which is what the installer is expecting because it is usually kicked off by the unattend that Bootcamp Assistant uses). The only in-box solution to do this is through Task Scheduler, but you could alternatively download psexec.exe and use that if you'd like.

I suspect that we've probably dodged this bullet in part by only supporting Mac desktops (and mostly iMacs at that). Perhaps their driver installer packages are less problematic.

But what you say makes a lot of sense. I don't understand Windows administration well enough to understand the context of the account executing it during an oobeSystem pass doing FirstLogonCommands, which is how we typically run it. I don't know whether this is helping or hurting.

from brigadier.

timsutton avatar timsutton commented on July 19, 2024 1

Thanks very much for posting your PS version! Could I include this version you're posting here directly in this repo?

It sounds like if invoking the install via a scheduled task run as SYSTEM is the most reliable way to do this, then I should probably copy your PS install section and try invoking it locally via the Python script, since you've already done the work to watch for the process completion. I suppose in order to do that, though, I may need to loosen PS execution policies first, or is it possible to execute a command with a one-time override so that I don't have to care about what state they were in before the script was run?

from brigadier.

nathanmcnulty avatar nathanmcnulty commented on July 19, 2024 1

You can definitely include it in the repo! I know there are a few things that could be done better, especially around the timing and reliability of the scheduled task, so as I iron those out, I'll submit the changes for you.

We have about 13,000 Mac's, and I've been using Configuration Manager prestages that use a trimmed down version of this script as part of the task sequence. I had added an extra step in the task sequence right after this script to validate that it was done before moving on (secondary insurance), so I'll have to spend some more time verifying that the timing logic itself is working as intended.

As for invoking it, you can just call "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" with the parameters "-ExecutionPolicy Bypass -File " which will avoid having to change execution policy on the system.

I think Task Scheduler is the best way to run as SYSTEM due to the fact that many company policies or AV vendors view PsExec as a potential security threat. The SysInternal tools are great and could be downloaded, extracted, and used for this purpose, probably more reliably even, but adds complexity and more dependencies.

Here's those tools:
https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

from brigadier.

timsutton avatar timsutton commented on July 19, 2024 1

Agreed. I know the Sysinternals tools are great for administration and diagnosis, but I'd rather just use mechanisms which are built-in or can be very easily bootstrapped.

Thanks for the pointer about the execution policy as well!

from brigadier.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.