-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCreate-DevDrive.ps1
74 lines (63 loc) · 2.51 KB
/
Create-DevDrive.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<#
.SYNOPSIS
Creates a dev drive for usage with Azure Image Builder
.DESCRIPTION
Creates a new dev drive and mounts it then sets up the various package folders and environment variables.
.EXAMPLE
.\dev-aib-createdevdrive.ps1 -Path c:\newdevdrive.vhdx -DriveLetter X
#>
# Parameter help description
param(
[Parameter(HelpMessage="Path to the VHD file to create")]
[ValidateScript({
if ([string]::IsNullOrWhiteSpace($_.Trim()))
{
throw "Path cannot be empty."
} else {
$true
}
})][string] $Path="c:\devdrive.vhdx", # Path to the VHD file to create
[Parameter(HelpMessage="Drive letter to mount the new VHD to")]
[ValidateScript({
if ([string]::IsNullOrWhiteSpace($_.Trim()))
{
throw "DriveLetter cannot be empty."
} else {
$true
}
})][string] $DriveLetter="D" # Drive letter to mount the new VHD to
)
$ErrorActionPreference = "Stop"
Write-Host "Creating new VHD at $Path"
New-VHD -Path $Path -SizeBytes 100GB -Dynamic -ErrorAction Stop
Write-Host "VHD created, mounting..."
$diskImage = Mount-DiskImage -ImagePath $Path -PassThru
Write-Host "VHD mounted, initializing..."
# Get the disk object
$disk = $diskImage | Get-Disk -ErrorAction Stop
# Initialize the disk
$disk | Initialize-Disk -PartitionStyle MBR -ErrorAction Stop
Write-Host "Disk initialized, creating partition..."
# Create a new partition on the disk
$partition = $disk | New-Partition -UseMaximumSize -ErrorAction Stop
Write-Host "Partition created, assigning drive letter $DriveLetter"
# Assign a drive letter to the partition
$partition | Set-Partition -NewDriveLetter $DriveLetter -ErrorAction Stop
Write-Host "Drive letter assigned, formatting as Dev Drive..."
# format as a dev drive, output the result
format ${DriveLetter}: /devdrv /q /y /v:DevDrive
fsutil devdrv query ${DriveLetter}:
Write-Host "Dev Drive formatted, creating packages folders and setting machine env vars..."
# create the various package folders and set their environment variables
mkdir ${DriveLetter}:\packages\npm
setx /M npm_config_cache ${DriveLetter}:\packages\npm
mkdir ${DriveLetter}:\packages\vcpkg
setx /M VCPKG_DEFAULT_BINARY_CACHE ${DriveLetter}:\packages\vcpkg
mkdir ${DriveLetter}:\.nuget\packages
setx /M NUGET_PACKAGES ${DriveLetter}:\.nuget\packages
mkdir ${DriveLetter}:\packages\pip
setx /M PIP_CACHE_DIR ${DriveLetter}:\packages\pip
mkdir ${DriveLetter}:\packages\cargo
setx /M CARGO_HOME ${DriveLetter}:\packages\cargo
mkdir ${DriveLetter}:\packages\maven
setx /M MAVEN_OPTS "-Dmaven.repo.local=${DriveLetter}:\packages\maven %MAVEN_OPTS%"