You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Parameter()]
$VirtualMachinePath = 'D:\VMs',
[Parameter()]
$VirtualMachineTemplate = 'D:\ISO\template.vhdx',
[Parameter()]
$Name = 'VM-DC01-Disk'
)
Import-DscResource -ModuleName xPendingReboot
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName ComputerManagementDsc
Import-DscResource -ModuleName CertificateDsc
Import-DscResource -ModuleName NetworkingDsc
Import-DscResource -ModuleName HyperVDsc
Import-DscResource -ModuleName xHyper-V
Node localhost
{
# Configure LCM to allow Windows to automatically reboot if needed. Note: NOT recommended for production!
LocalConfigurationManager
{
# Set this to $true to automatically reboot the node after a configuration that requires reboot is applied. Otherwise, you will have to manually reboot the node for any configuration that requires it. The default (recommended for PRODUCTION servers) value is $false.
RebootNodeIfNeeded = $true
# The thumbprint of a certificate used to secure credentials passed in a configuration.
CertificateId = $node.Thumbprint
}
# Install Windows Feature "Hyper-V Services".
WindowsFeature HyperV
{
Ensure = 'Present'
Name = 'Hyper-V'
}
WindowsFeature HyperVPowerShell
{
Ensure = 'Present'
Name = 'Hyper-V-PowerShell'
}
# Dynamically build the 'DependsOn' array for the 'VMHyperV' feature
# based on the number of virtual switches specified
$VMHyperVDependsOn = @('[WindowsFeature]HyperV','[WindowsFeature]HyperVPowerShell')
# Create a switch to be used by the VM
VMSwitch switch
{
Name = 'Test-Switch'
Ensure = 'Present'
Type = 'Internal'
}
# Create new VHD file.
File NewVHD1
{
SourcePath = $VirtualMachineTemplate
DestinationPath = Join-path (Split-Path $VirtualHardDiskPath) "$name.vhdx"
Type = 'File'
Ensure = 'Present'
}
#Vhd NewVHD1
#{
# Ensure = 'Present'
# Name = $name
# Path = (Split-Path $VirtualHardDiskPath)
# Generation = 'Vhdx'
# ParentPath = $VirtualHardDiskPath
#}
# 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 CopyDSCConfigPFX
{
VhdPath = Join-path (Split-Path $VirtualHardDiskPath) "$name.vhdx"
FileDirectory = @(
# Pending.mof
DSC_FileDirectory {
SourcePath = 'C:\DSCConfigs\HADC\DC01\Localhost.mof'
DestinationPath = "Temp\Pending.mof"
Ensure = 'Present'
}
# meta.mof
DSC_FileDirectory {
SourcePath = 'C:\DSCConfigs\HADC\DC01\localhost.meta.mof'
DestinationPath = "Windows\System32\Configuration\MetaConfig.mof"
Type = 'File'
Ensure = 'Present'
}
# xPFX
DSC_FileDirectory {
SourcePath = 'C:\DSCConfigs\PFX'
DestinationPath = "DSCConfigs\PFX"
type = 'Directory'
Recurse = $True
Ensure = 'Present'
}
# xModules
DSC_FileDirectory {
SourcePath = 'C:\DSCConfigs\Modules'
DestinationPath = "DSCConfigs\Modules"
type = 'Directory'
Recurse = $True
Ensure = 'Present'
}
)
DependsOn = '[File]NewVHD1'
}
# create the testVM out of the vhd.
VMHyperV TestVM
{
Name = "$($name)_vm"
SwitchName = 'Test-Switch'
VhdPath = Join-path (Split-Path $VirtualHardDiskPath) "$name.vhdx"
Path = "$VirtualMachinePath" + "\" + "$($name)_vm"
ProcessorCount = 2
MaximumMemory = 4GB
MinimumMemory = 1GB
RestartIfNeeded = $true
DependsOn = '[VMSwitch]switch', '[File]NewVHD1', '[VhdFile]CopyDSCConfigPFX'
State = 'Running'
Generation = '2'
SecureBoot = $true
}
}
}`
Operating system the target node is running
Server 2022 standalone
PowerShell version and build the target node is running
Latest
HyperVDsc version
Latest
The text was updated successfully, but these errors were encountered:
Problem description
Seems that files are not copied to vhdx
I got a vhdx with windows server already installed on it.
When i run the DSC configuration seems okee but files are not found on the VHDX
Resources to be copied are located on Hyper v host C:\DSCConfigs
Need to be copied inside VHDX C:\Temp
Verbose logs
DSC configuration
Suggested solution
Working copy to vhdx to function to eventualy do:
`Configuration VM-DC01
{
param
(
[Parameter()]
$VirtualHardDiskPath = 'D:\VMDisks\disk.vhdx',
}`
Operating system the target node is running
PowerShell version and build the target node is running
HyperVDsc version
The text was updated successfully, but these errors were encountered: