-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathscript.erb
More file actions
86 lines (65 loc) · 2.96 KB
/
Copy pathscript.erb
File metadata and controls
86 lines (65 loc) · 2.96 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
<%#
kind: script
name: Windows Install
oses:
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
This template accepts the following parameters:
-windowsEdition: Windows 2012|2012R2 SERVER STANDARD|ENTERPRISE|DATACENTER|CORE
-deploymentShare: Path to share containing Windows images
-deploymentShareUser: Username to access share
-deploymentSharePassword: Password to access share
%>
param
(
$rootPath
)
$ErrorActionPreference = "Stop"
$logPath = Join-Path $rootPath "InstallWindows.log"
$driveLetter = "t:"
$windowsInstallPath = "<%= @host.params['deploymentShare'] %>"
$installWim = "install.wim"
$localForemanPath = "c:\Foreman\"
Import-Module (Join-Path $rootPath "BuildFunctions.ps1")
Start-Transcript $logPath | Out-Null
Write-Host ("InstallWindows.ps1 started at " + (Get-Date))
#1. Configure disk layout
Write-Host "Configuring disk"
<%= @host.diskLayout %>
#2. Mount install share
Write-Host "Mounting install share ${windowsInstallPath} to ${driveLetter}"
net use $driveLetter $windowsInstallPath /user:<%= @host.params['deploymentShareUser'] %> <%= @host.params['deploymentSharePassword'] %>
#MountDrive $driveLetter $windowsInstallPath
#3. Expanding WIM
$installurl = "<%= @host.operatingsystem.medium_uri(@host) %>"
$installWimPath = Join-Path (HttpPathToFSPath $driveLetter $installurl) $installWim
$installimage = "<%= @host.params['windowsEdition'] %>"
Write-Host ("Expanding image " + $installimage + " from WIM " + $installWimPath);
Expand-WindowsImage -ImagePath $installWimPath -Name $installimage -ApplyPath C:\
#4. Add boot sector
Write-Host "Adding boot sector"
bootsect /nt60 C:
#5. Add windows to BCD path
Write-Host "Adding BCD chain"
C:\Windows\System32\bcdboot C:\Windows /l en-US
#6. Copy all Foreman files to new drive
Write-Host "Copying installer scripts to the host"
New-Item -Path $localForemanPath -ItemType directory | Out-Null
Copy-Item "x:\Foreman\*" $localForemanPath | Out-Null
New-Item -Path "c:\Windows\Panther" -ItemType directory -ErrorAction SilentlyContinue | Out-Null
Copy-Item (Join-Path $localForemanPath "unattend.xml") "c:\Windows\Panther\unattend.xml"
#7. Apply the unattend
Write-Host "Applying unattend.xml"
New-Item -Path "c:\DismTemp\" -ItemType directory | Out-Null
Apply-WindowsUnattend -UnattendPath "c:\Windows\Panther\unattend.xml" -Path C:\ -ScratchDirectory "C:\DismTemp\"
#8. Write SetupComplete to finish install next boot
$setupComplete = "c:\Windows\Setup\Scripts\SetupComplete.cmd"
New-Item ([System.IO.Path]::GetDirectoryName($setupComplete)) -ItemType Directory -ErrorAction SilentlyContinue
New-Item $setupComplete -ItemType file -Value "powershell -ExecutionPolicy Unrestricted c:\Foreman\ConfigureWindows.ps1"
#9. Notify foreman build is complete
Invoke-WebRequest "<%= foreman_url %>" -UseBasicParsing | Out-Null
Write-Host ("InstallWindows.ps1 finished at " + (Get-Date))
Stop-Transcript | Out-Null
Copy-Item -Path (Join-Path $rootPath "InstallWindows.log") -Destination $localForemanPath | Out-Null
Restart-Computer