Skip to content

Instantly share code, notes, and snippets.

@JohnMichaelMiller
Last active April 19, 2022 17:23
Show Gist options
  • Save JohnMichaelMiller/2573a7affd2021a946d2b767c6579f87 to your computer and use it in GitHub Desktop.
Save JohnMichaelMiller/2573a7affd2021a946d2b767c6579f87 to your computer and use it in GitHub Desktop.
PowerShell code for building Windows PCs using BoxStarter

#Build.Machine

On the build machine

Create a gist to store the generate code Upload the bootstrap file from this gist to the new gist Fork the repo Make changes specific to the machine types Up the code to point to the new gist Run the build code.

On the target machine

Down load the gist as a zip

From a Administrator PowerShell, if Get-ExecutionPolicy returns Restricted, run:

if ((Get-ExecutionPolicy) -eq 'Restricted') { write-output 'Run the following command in an administrator PowerShell' write-output 'Set-ExecutionPolicy Unrestricted -Force' }

Unblock the files

gci | unblock-file

Run boostrap.ps1 passing the machine type

[CmdletBinding()]
param (
[Parameter()]
[string]
$build = 'socrates'
)
write-output "start $build $($MyInvocation.MyCommand.Source)"
$env:BuildJsonFile = ".\$build.machine.json"
if (test-path $env:BuildJsonFile) {
# Install Boxstarter if not already installed
$_boxstarter_path = 'C:\ProgramData\Boxstarter\BoxstarterShell.ps1'
if (!(Test-Path $_boxstarter_path)) {
". { Invoke-WebRequest -useb 'http://boxstarter.org/bootstrapper.ps1' } | Invoke-Expression; get-boxstarter -Force"
. { Invoke-WebRequest -useb 'http://boxstarter.org/bootstrapper.ps1' } | Invoke-Expression; get-boxstarter -Force
}
Disable-UAC # Prevent UAC interference
$buildCode = ".\$build.machine.ps1"
if (test-path $buildCode) {
write-output "Invoke-ChocolateyBoxstarter -BootstrapPackage $buildCode -KeepWindowOpen"
Invoke-ChocolateyBoxstarter -BootstrapPackage $buildCode -KeepWindowOpen
}
else {
write-output "file $buildCode not found."
}
}
else {
write-output "file $($env:BuildJsonFile) not found."
}
write-output "end $build $($MyInvocation.MyCommand.Source)"
{
"$schema": "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate": "2022-04-16T00:58:55.658-07:00",
"Sources": [
{
"Packages": [
{
"PackageIdentifier": "Malwarebytes.Malwarebytes"
},
{
"PackageIdentifier": "Google.Chrome"
},
{
"PackageIdentifier": "LogMeIn.LastPass"
},
{
"PackageIdentifier": "9NBHCS1LX4R0"
},
{
"PackageIdentifier": "CodeJelly.Launchy"
},
{
"PackageIdentifier": "Notepad++.Notepad++"
},
{
"PackageIdentifier": "WinDirStat.WinDirStat"
},
{
"PackageIdentifier": "Spotify.Spotify"
},
{
"PackageIdentifier": "Zoom.Zoom"
},
{
"PackageIdentifier": "SlackTechnologies.Slack"
},
{
"PackageIdentifier": "Google.Chrome.Dev"
},
{
"PackageIdentifier": "Mozilla.Firefox.DeveloperEdition"
},
{
"PackageIdentifier": "BraveSoftware.BraveBrowser.Dev"
},
{
"PackageIdentifier": "7zip.7zip"
},
{
"PackageIdentifier": "Lexikos.AutoHotkey"
},
{
"PackageIdentifier": "ScooterSoftware.BeyondCompare4"
},
{
"PackageIdentifier": "Git.Git"
},
{
"PackageIdentifier": "GitHub.GitLFS"
},
{
"PackageIdentifier": "Microsoft.GitCredentialManagerCore"
},
{
"PackageIdentifier": "Microsoft.VisualStudioCode"
},
{
"PackageIdentifier": "Microsoft.PowerShell"
},
{
"PackageIdentifier": "Telerik.Fiddler.Everywhere"
},
{
"PackageIdentifier": "Python.Python.3"
},
{
"PackageIdentifier": "Microsoft.WindowsTerminal"
},
{
"PackageIdentifier": "Hashicorp.Vagrant"
},
{
"PackageIdentifier": "Microsoft.Teams "
},
{
"PackageIdentifier": "9P7KNL5RWT25"
},
{
"PackageIdentifier": "WestWind.MarkdownMonster"
},
{
"PackageIdentifier": "Microsoft.dotNetFramework"
},
{
"PackageIdentifier": "Microsoft.dotnet"
},
{
"PackageIdentifier": "Postman.Postman"
},
{
"PackageIdentifier": "Microsoft.AzureCLI"
},
{
"PackageIdentifier": "Microsoft.Bicep"
},
{
"PackageIdentifier": "Microsoft.AzureStorageExplorer"
},
{
"PackageIdentifier": "Microsoft.AzureStorageEmulator"
},
{
"PackageIdentifier": "Microsoft.AzureFunctionsCoreTools"
},
{
"PackageIdentifier": "Microsoft.AzureDataStudio"
},
{
"PackageIdentifier": "Microsoft.AzureCosmosEmulator"
},
{
"PackageIdentifier": "Microsoft.AzureDataCLI"
},
{
"PackageIdentifier": "Amazon.AWSCLI"
}
],
"SourceDetails": {
"Argument": "https://winget.azureedge.net/cache",
"Identifier": "Microsoft.Winget.Source_8wekyb3d8bbwe",
"Name": "winget",
"Type": "Microsoft.PreIndexed.Package"
}
}
],
"WinGetVersion": "1.2.10751"
}
# Generated by build.machines on 4/19/2022 9:52:01 AM$
Write-BoxstarterMessage 'start call.winget.ps1'
$jsonFile = $env:BuildJsonFile
if (test-path $jsonFile) {
Write-BoxstarterMessage 'Running winget import to install Windows Store packages'
winget import `
--ignore-unavailable `
--ignore-versions `
--accept-package-agreements `
--accept-source-agreements `
--import-file $jsonFile
}
else {
Write-BoxstarterMessage "winget json file ($jsonFile) not found"
throw "winget json file ($jsonFile) not found"
}
Write-BoxstarterMessage 'end call.winget.ps1'
wsl -install
wsl -install -distribution Ubuntu
choco upgrade westwindwebsurge --confirm
choco upgrade vscode-python --confirm
choco upgrade vscode-markdownlint --confirm
choco upgrade vscode-python --confirm
choco upgrade vscode-yaml --confirm
choco upgrade vscode-pull-request-github --confirm
choco upgrade vscode-gitlens --confirm
choco upgrade vscode-powershell --confirm
choco upgrade vscode-autohotkey --confirm
choco install vscode-csharp --confirm
git config --global user.email "jmiller@pdata.com"
git config --global user.name "John M. Miller"
git config --global core.editor "'C:\Program Files\Notepad\notepad.exe' -multiInst -notabbar -nosession -noPlugin"
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global pull.rebase true
git config --global diff.tool bc
git config --global difftool.bc.path "c:/Program Files/Beyond Compare 4/bcomp.exe"
git config --global merge.tool bc
git config --global mergetool.bc.path "c:/Program Files/Beyond Compare 4/bcomp.exe"
$currentLocation = Get-Location
if (-not (test-path c:\git)) { mkdir c:\git }
Set-Location c:\git
$repos = @(
'https://github.com/JohnMichaelMiller/build.machines.git',
'https://gist.github.com/ff15ca29ac2a37ddec7fb0d06124c41d.git',
'https://gist.github.com/2573a7affd2021a946d2b767c6579f87.git',
'https://github.com/JohnMichaelMiller/acloud.guru.git',
'https://github.com/JohnMichaelMiller/Kata.git',
'https://github.com/JohnMichaelMiller/TemperatureConversionGrader.git',
'https://github.com/Juxce/tuneage-azure-functions.git'
'https://github.com/Juxce/tuneage-api-dotnet.git'
)
$repos | ForEach-Object {
$folder = ($_.Substring( $_.LastIndexOf('/') + 1 )).replace('.git', '')
write-debug "folder($folder)"
if (-not (test-path $folder )) {
write-verbose "creating folder $folder"
mkdir $folder
write-verbose "cloning repo $_"
git clone $_
Set-Location $folder
}
else {
write-verbose "getting latest from repo $_"
Set-Location $folder
git pull --rebase
}
if ($_.contains('Juxce')) {
git config --local user.email "jmm@juxce.com"
}
else {
git config --local user.email "johnmichaelmiller@outlook.com"
}
git config user.email
Set-Location ..
}
set-Location $currentLocation
choco upgrade vscode-azurerm-tools --confirm
choco upgrade aws-vault --confirm
choco upgrade awstools.powershell --confirm
choco upgrade awslambdapscore --confirm
choco upgrade terraform --confirm
choco upgrade Terraform-Docs --confirm
{
"$schema": "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate": "2022-04-16T00:58:55.658-07:00",
"Sources": [
{
"Packages": [
{
"PackageIdentifier": "Malwarebytes.Malwarebytes"
},
{
"PackageIdentifier": "CodecGuide.K-LiteCodecPack.Full"
},
{
"PackageIdentifier": "Microsoft.SQLServer.2019.Express"
},
{
"PackageIdentifier": "Microsoft.SQLServerManagementStudio"
},
{
"PackageIdentifier": "Plex.PlexMediaServer"
},
{
"PackageIdentifier": "Valve.Steam"
},
{
"PackageIdentifier": "2BrightSparks.SyncBackFree"
},
{
"PackageIdentifier": "XBMCFoundation.Kodi"
},
{
"PackageIdentifier": "9P4CLT2RJ1RS"
}
],
"SourceDetails": {
"Argument": "https://winget.azureedge.net/cache",
"Identifier": "Microsoft.Winget.Source_8wekyb3d8bbwe",
"Name": "winget",
"Type": "Microsoft.PreIndexed.Package"
}
}
],
"WinGetVersion": "1.2.10751"
}
# Generated by build.machines on 4/19/2022 9:52:01 AM$
Write-BoxstarterMessage 'start call.winget.ps1'
$jsonFile = $env:BuildJsonFile
if (test-path $jsonFile) {
Write-BoxstarterMessage 'Running winget import to install Windows Store packages'
winget import `
--ignore-unavailable `
--ignore-versions `
--accept-package-agreements `
--accept-source-agreements `
--import-file $jsonFile
}
else {
Write-BoxstarterMessage "winget json file ($jsonFile) not found"
throw "winget json file ($jsonFile) not found"
}
Write-BoxstarterMessage 'end call.winget.ps1'
{
"$schema": "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate": "2022-04-16T00:58:55.658-07:00",
"Sources": [
{
"Packages": [
{
"PackageIdentifier": "Malwarebytes.Malwarebytes"
},
{
"PackageIdentifier": "Google.Chrome"
},
{
"PackageIdentifier": "LogMeIn.LastPass"
},
{
"PackageIdentifier": "9NBHCS1LX4R0"
},
{
"PackageIdentifier": "CodeJelly.Launchy"
},
{
"PackageIdentifier": "Notepad++.Notepad++"
},
{
"PackageIdentifier": "WinDirStat.WinDirStat"
},
{
"PackageIdentifier": "Spotify.Spotify"
},
{
"PackageIdentifier": "Zoom.Zoom"
},
{
"PackageIdentifier": "SlackTechnologies.Slack"
}
],
"SourceDetails": {
"Argument": "https://winget.azureedge.net/cache",
"Identifier": "Microsoft.Winget.Source_8wekyb3d8bbwe",
"Name": "winget",
"Type": "Microsoft.PreIndexed.Package"
}
}
],
"WinGetVersion": "1.2.10751"
}
# Generated by build.machines on 4/19/2022 9:52:01 AM$
Write-BoxstarterMessage 'start call.winget.ps1'
$jsonFile = $env:BuildJsonFile
if (test-path $jsonFile) {
Write-BoxstarterMessage 'Running winget import to install Windows Store packages'
winget import `
--ignore-unavailable `
--ignore-versions `
--accept-package-agreements `
--accept-source-agreements `
--import-file $jsonFile
}
else {
Write-BoxstarterMessage "winget json file ($jsonFile) not found"
throw "winget json file ($jsonFile) not found"
}
Write-BoxstarterMessage 'end call.winget.ps1'
{
"$schema": "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate": "2022-04-16T00:58:55.658-07:00",
"Sources": [
{
"Packages": [
{
"PackageIdentifier": "Malwarebytes.Malwarebytes"
}
],
"SourceDetails": {
"Argument": "https://winget.azureedge.net/cache",
"Identifier": "Microsoft.Winget.Source_8wekyb3d8bbwe",
"Name": "winget",
"Type": "Microsoft.PreIndexed.Package"
}
}
],
"WinGetVersion": "1.2.10751"
}
# Generated by build.machines on 4/19/2022 9:52:01 AM$
Write-BoxstarterMessage 'start call.winget.ps1'
$jsonFile = $env:BuildJsonFile
if (test-path $jsonFile) {
Write-BoxstarterMessage 'Running winget import to install Windows Store packages'
winget import `
--ignore-unavailable `
--ignore-versions `
--accept-package-agreements `
--accept-source-agreements `
--import-file $jsonFile
}
else {
Write-BoxstarterMessage "winget json file ($jsonFile) not found"
throw "winget json file ($jsonFile) not found"
}
Write-BoxstarterMessage 'end call.winget.ps1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment