-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDeployWindowsVHDDomain.ps1
More file actions
64 lines (52 loc) · 1.82 KB
/
DeployWindowsVHDDomain.ps1
File metadata and controls
64 lines (52 loc) · 1.82 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
param(
$SystemDrive='L',
# Drive Letter being assigned to Windows Drive
#
$OSDrive='L',
# Netbios name of computer and VMName
#
$Computername='Contoso-Win7'
)
$VHD=Convert-WimtoVhd -Wimfile C:\Windows7\install.wim -vm $Computername
$Mount=Mount-vhd $VHD
Add-PartitionAccessPath -DiskId
# Clear out the old Unattend.xml file if it exists
#
Remove-Item -Path Unattend.xml -Force -ErrorAction SilentlyContinue
# Create an Unattend.XML to define the Computername, owner,
# Timezone and default Admin Password
#
$XMLContent=New-UnattendXMLContent -Computername $Computername -Timezone 'Eastern Standard Time' -Owner 'Contoso' -Organization 'Contoso' -AdminPassword 'P@ssw0rd' -Online -DomainName Contoso -DomainAccount 'Administrator' -DomainPassword 'P@ssw0rd'
# Create the Unattend.xml file
#
New-Item -ItemType File -Name Unattend.xml -Force | Out-Null
Add-content Unattend.xml -Value $XMLContent
# Inject the Unattend.xml file into the VHD image
#
Copy .\Unattend.xml "$OSdrive`:\Windows\system32\sysprep"
# Build the post Unattend.xml - Pre login script
# This will define the static IP address and Perform an
# Offline Domain Join from the provide domainjoin.djoin file
#
$SetupCompleteCMD=@"
"@
# Remove the old SetupComplete.CMD if it exists
#
Remove-Item -Path SetupComplete.cmd -Force -ErrorAction SilentlyContinue
# Create the new one
#
New-Item -ItemType File -Name SetupComplete.cmd -Force | Out-Null
Add-content SetupComplete.cmd -Value $SetupCompleteCMD
# Inject into the disk image
#
Copy .\SetupComplete.cmd "$OSdrive`:\Windows\setup\scripts"
# Remove Drive Letter from Assigned Disk and place
# back into pool.
#
Remove-DriveLetter -DriveLetter $OSDrive
# Disconnect VHD
#
Dismount-VHD -Path $vhd
# From this point forward you can manually create a
# Virtual Machine in Hyper-V or use this VHD file for
# booting on a Physical Disk