-
Notifications
You must be signed in to change notification settings - Fork 0
/
DscCreateLab.ps1
138 lines (127 loc) · 5.52 KB
/
DscCreateLab.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
$configData = @{
AllNodes = @(
@{
NodeName = 'Psam-H01'
Role = 'VM'
# Modules that is needed
xNetworkingPath = "$(gmo xNetworking -ListAvailable | % modulebase | select -first 1)"
xComputerManagementpath = "$(gmo xComputerManagement -ListAvailable | % modulebase | select -first 1)"
xPendingReboot = "$(gmo xPendingReboot -ListAvailable | % modulebase | select -first 1)"
XActiveDirectory = "$(gmo XActiveDirectory -ListAvailable | % modulebase | select -first 1)"
xSQLServer = "$(gmo xSQLServer -ListAvailable | % modulebase | select -first 1)"
unattendedFilePathToCopy = "$((Resolve-Path '.\unattend.xml').Path)"
}
)
}
Configuration Createlab
{
Param
(
$BaseDir = (Get-Location).path,
#[string[]]$NodeName = 'localhost',
[string]$Name = 'Localhost',
$BaseVhdPath = 'H:\SourceDisk\2012R2_201607.vhdx',
$MinMemory = 1GB, # amount of memory in mb
$MaxMemory = 4GB, # amount of memory in mb
$StartupMemory = 2GB, # amount of memory in mb
$CPU = '2', # number of CPUs to allocate
$SwitchName = 'Lab', # Switch name for Lab
$SourceBase = 'C:\Iso\Source'
)
# Files to be injected
$DSCSourcePath = "$BaseDir\ServerConfig\$name.mof"
$DSCRebootTrueSourcePath = "$BaseDir\ServerConfig\$name.meta.mof"
# Where to inject te modules
$ModuleTargetpath = "Program Files\WindowsPowerShell\Modules\"
#DestinationPath
$DestinationPath = "h:\Lab\$name"
Import-DscResource -ModuleName xHyper-v, PSDesiredStateConfiguration
Node $AllNodes.Where{$_.Role -eq "VM"}.Nodename
{
File Folder {
Type = 'Directory'
DestinationPath = $DestinationPath
Ensure = "Present"
}
# Create a Switch to be used by the VM (Internal)
xVMSwitch Lab
{
Ensure = 'Present'
Name = 'Lab'
Type = 'Internal'
}
# Create a differencing VHDX (Diff vhdx)
xVHD NewVHD1
{
Ensure = 'Present'
Name = $name
Path = $DestinationPath
Generation = "VHDX"
ParentPath = $BaseVhdPath
DependsOn = '[File]Folder'
}
xVhdFile Copyfiles
{
VhdPath = "$DestinationPath\$name.vhdx"
FileDirectory = @(
MSFT_xFileDirectory {
SourcePath = $Node.unattendedFilePathToCopy
DestinationPath = 'Unattend.xml'
}
MSFT_xFileDirectory {
SourcePath = $Node.xNetworkingPath
DestinationPath = "$ModuleTargetpath\xNetworking\"
}
MSFT_xFileDirectory {
SourcePath = $Node.xComputerManagementpath
DestinationPath = "$ModuleTargetpath\xComputerManagement\"
}
MSFT_xFileDirectory {
SourcePath = $Node.xPendingReboot
DestinationPath = "$ModuleTargetpath\xPendingReboot\"
}
MSFT_xFileDirectory {
SourcePath = $DSCSourcePath
DestinationPath = "Windows\System32\Configuration\pending.mof"
}
MSFT_xFileDirectory {
SourcePath = $DSCRebootTrueSourcePath
DestinationPath = "Windows\System32\Configuration\metaconfig.mof"
}
if (($name -eq 'DC1') -or ($name -eq 'DC2')){
MSFT_xFileDirectory {
SourcePath = $Node.XActiveDirectory
DestinationPath = "$ModuleTargetpath\XActiveDirectory\"
}
}
if (($name -eq 'SQL1') -or ($name -eq 'SQL2')){
MSFT_xFileDirectory {
SourcePath = "$sourceBase\SQL2014"
DestinationPath = "Install\SQL"
}
MSFT_xFileDirectory {
SourcePath = $Node.xSQLServer
DestinationPath = "$ModuleTargetpath\xSQLServer"
}
}
)
DependsOn = "[xVHD]NewVhd1"
}
xVMHyperV Server
{
Name = $name
SwitchName = $SwitchName
VhdPath = "$DestinationPath\$name.vhdx"
MaximumMemory = $MaxMemory
MinimumMemory = $MinMemory
StartupMemory = $StartupMemory
EnableGuestService = $true
RestartIfNeeded = $true
ProcessorCount = $Cpu
Path = $Node.DestinationPath
Generation = 2
State = 'Running'
DependsOn = '[xVHD]NewVHD1','[xVMSwitch]Lab','[xvhdFile]CopyFiles','[File]Folder'
}
}
}