-
Notifications
You must be signed in to change notification settings - Fork 65
/
Sample_EndToEndHyperV_RunningVM.ps1
65 lines (57 loc) · 1.58 KB
/
Sample_EndToEndHyperV_RunningVM.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
<#
.DESCRIPTION
End to end sample for running a VM in HyperV
#>
Configuration Example
{
param
(
[Parameter()]
$vhdPath = 'C:\temp\disk.vhdx',
[Parameter()]
$Name = 'Disk1',
[Parameter()]
$unattendedFilePathToCopy = 'C:\Media\unattended.xml'
)
Import-DscResource -ModuleName 'HyperVDsc'
# Create a switch to be used by the VM
VMSwitch switch
{
Name = 'Test-Switch'
Ensure = 'Present'
Type = 'Internal'
}
# Create new VHD file.
Vhd NewVHD1
{
Ensure = 'Present'
Name = $name
Path = (Split-Path $vhdPath)
Generation = 'vhd'
ParentPath = $vhdPath
}
# Customize VHD by copying a folders/files to the VHD before a VM can be created
# Example below shows copying unattended.xml before a VM can be created
VhdFile CopyUnattendedXml
{
VhdPath = $vhdPath
FileDirectory = DSC_FileDirectory
{
SourcePath = $unattendedFilePathToCopy
DestinationPath = 'unattended.xml'
}
}
# create the testVM out of the vhd.
VMHyperV TestVM
{
Name = "$($name)_vm"
SwitchName = 'Test-Switch'
VhdPath = Join-path (Split-Path $vhdPath) "$name.vhd"
ProcessorCount = 2
MaximumMemory = 1GB
MinimumMemory = 512MB
RestartIfNeeded = $true
DependsOn = '[VHD]NewVHD1', '[VMSwitch]switch', '[VhdFile]CopyUnattendxml'
State = 'Running'
}
}