A PowerShell module that allows you to easily create a terse re-pave script for a Windows Machine making heavy use of Chocolatey.
It focusses on speed and idempotency allowing you to add to the script as you go about the business of adding software to your machine. That way when it comes time to do the next repave it's good to go rather than having to spend half a day figuring out the missing software. If something is already installed then it will immediately skip it rather than invoking cinst
to find out meaning the script should fly through to the end if you are simply adding a new installation at the bottom.
Furthermore, if something goes wrong at any point then it will fail fast and it will store an installation log for you so you can review what it did.
Look at robdmoore.ps1
or MattDavies.ps1
for examples of how to use the scripts. These are the scripts that we actually use for our machines.
Feel free to fork this and add your own script. Also feel free to send pull requests or raise issues if you have ideas / questions.
Get us via Twitter at: @robdmoore / @mdaviesnet.
To get started all you need is this in a .ps1
file:
Import-Module "$(Split-Path $MyInvocation.MyCommand.Path)\repave.psm1" -Force
Invoke-Repave {
# Stuff to install
}
When you run it you must be in admin mode and after running there will be an repave.log
file with the output and a todo.txt
file with items for further action (unless you ran the script from PowerShell ISE, in which case there is no repave.log
).
Invokes $script
as a code block after setting up and shutting down the repave environment before and after it respectively.
Setting up the environment involves:
- Writing an error and exiting with non-zero exit code if the script is not executed with admin privileges
- Invoking
Start-Script
(see below) - Creating a try block
- Creating an
Installers
directory if it doesn't already exist (used as a cache for installers that are downloaded) - If the user is running in PowerShell ISE then outputting a warning that there will be no transcript
- If the user is not running in PowerShell ISE then starting a transcript for
repave.log
in append mode (i.e. subsequent runs will append to the log) - Invoking
Install-Chocolatey
(see below) - Invoking
Install-WebPI
(see below)
- Creating an
Shutting down the environment involves:
- Write a warning to remind the user to clear the temp path
- If a transcript is running then stop it
- Catch any exceptions and:
- Write an error
- If a transcript is running then stop it
- Exit with non-zero exit code
- Gets the path of the
.ps1
script being executed and saves it to a global variable called$scriptpath
; you can use this variable from your scripts - Changes directory to
$scriptpath
so any local file references will be local to the script no matter what the working directory was when the script was first executed - Sets
$ErrorActionPreference
tostop
so any errors will cause an exception to throw and the repave script to early exit- There is currently a bug where problems in programs that are executed (e.g.
cinst
) don't propagate out
- There is currently a bug where problems in programs that are executed (e.g.
Install Chocolatey if not already installed (and record which Chocolatey packages were installed when the script was first run so it can detect if it should invoke cinst
when installing packages - this is a huge speed boost on subsequent script runs).
Returns the value of the global $scriptpath
variable setup by Start-Script
/ Invoke-Repave
.
Returns $true
if running with admin priviliges.
Returns $true
if running in a Virtual Machine.
Sets "Show Hidden Files", "Show File Extensions" and "Show System Files" in Windows Explorer.
Install of:
C:\Program Files (x86)\Git\bin
in%PATH%
- Copying the
.ssh
folder (if present relative to the script) to~
if not already there- If it is present then TortoiseGit is configured to use
ssh.exe
rather thanPLink.exe
- If it is present then TortoiseGit is configured to use
- Copies the
.gitconfig
file (if present relative to the script) to~
if not already there - Copies the
.gitconfig.work
file (if present relative to the script) to$workFolder
if not already there
Installs Visual Studio 2019 Professional.
Reloads the %PATH%
and appends the given path to the end of it if it's not already in there.
Pins the given $exe
inside of the given $path
to the taskbar.
Pins Chrome to the taskbar.
Pins Visual Studio 2019 to the taskbar.
Installs the given Chocolatey package if it's not already installed. Optionally pass -InstallArgs
to add extra Chocolatey installation arguments or -RunIfInstalled
to run some code if the given package is being installed.
Writes a warning of $message and appends that message to todo.txt
.
Adds a favourite link in Windows Explorer with the given name pointing to the given folder location.