Search code examples
powershelldsc

copying MOF file to vhd (xvhdFile) before boot


I'm working on a lab DSC build on a single server. I have a mof file for a server (vhdx) that I'm copying to c:\windows\system32\configuraiton\pending.mof. The idea being that at boot, the system will apply the mof and the system will be configured.

Unfortunately, the mof file isn't being copied. I have other entries under xVhdFile that are being copied (unattended.xml, DSC resource directories) but not the mof. Anyone know why?

Here is the xVhdFile entry:

xVhdFile "CopyUnattendedXml DC01"
{
    VhdPath =  "F:\VMs\DC01\DC01`.vhdx"
    FileDirectory =  @(

        # Pending.mof
        MSFT_xFileDirectory {
            SourcePath = 'F:\DSCScripts\Lab01\ForestRoot\Localhost.mof'
            DestinationPath = "\Windows\Sytem32\Configuration\Pending.mof" 
        }

        # unattend.xml
        MSFT_xFileDirectory {
            SourcePath = 'F:\VMs\Sysprep\2016DataCenterEval_2.xml'
            DestinationPath = "\Windows\System32\Sysprep\Unattend.xml"
        }

        # xActiveDirectory
        MSFT_xFileDirectory {
            SourcePath = 'C:\Program Files\WindowsPowerShell\Modules\xActiveDirectory\'
            DestinationPath = "\Program Files\WindowsPowerShell\Modules\" 
            type    = 'Directory'
            Recurse = $True
        }

        # xNetworking
        MSFT_xFileDirectory {
            SourcePath = 'C:\Program Files\WindowsPowerShell\Modules\xNetworking\'
            DestinationPath = "\Program Files\WindowsPowerShell\Modules\" 
            type    = 'Directory'
            Recurse = $True
        }
    )
    DependsOn = "[File]CopyBaseImage DC01"
}

Thanks

Verbose output:

VERBOSE: [WIN-LBCPOR4PDR5]: LCM:  [ Start  Resource ]  [[xVhdFile]CopyUnattendedXml DC01]
VERBOSE: [WIN-LBCPOR4PDR5]: LCM:  [ Start  Test     ]  [[xVhdFile]CopyUnattendedXml DC01]
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Alias
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] C
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Cert
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] D
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] E
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Env
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] F
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Function
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] H
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] HKCU
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] HKLM
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Variable
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] WSMan
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] H:\
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] DestinationPath => \Windows\Sytem32\Configuration\Pending.mof
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Recurse => True
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Force => True
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Type => File
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Ensure => True
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Content =>
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] SourcePath => F:\DSCScripts\Lab01\ForestRoot\Localhost.mof
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Attributes =>
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Testing the file with relative VHD destination
\Windows\Sytem32\Configuration\Pending.mof
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Test returned False
VERBOSE: [WIN-LBCPOR4PDR5]: LCM:  [ End    Test     ]  [[xVhdFile]CopyUnattendedXml DC01]  in 2.4530 seconds.
VERBOSE: [WIN-LBCPOR4PDR5]: LCM:  [ Start  Set      ]  [[xVhdFile]CopyUnattendedXml DC01]
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Alias
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] C
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Cert
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] D
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] E
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Env
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] F
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Function
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] H
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] HKCU
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] HKLM
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Variable
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] WSMan
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] DestinationPath => \Windows\Sytem32\Configuration\Pending.mof
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Recurse => True
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Force => True
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Type => File
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Ensure => True
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Content =>
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] SourcePath => F:\DSCScripts\Lab01\ForestRoot\Localhost.mof
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Attributes =>
VERBOSE: [WIN-LBCPOR4PDR5]:                            [[xVhdFile]CopyUnattendedXml DC01] Setting the VHD file Copy
VERBOSE: [WIN-LBCPOR4PDR5]: LCM:  [ End    Set      ]  [[xVhdFile]CopyUnattendedXml DC01]  in 1.6880 seconds.
VERBOSE: [WIN-LBCPOR4PDR5]: LCM:  [ End    Resource ]  [[xVhdFile]CopyUnattendedXml DC01]

Solution

  • You have a typo. Sytem32 should be System32. This line:

    DestinationPath = "\Windows\Sytem32\Configuration\Pending.mof" 
    

    Becomes:

    DestinationPath = "\Windows\System32\Configuration\Pending.mof" 
    

    The file was being copied just not where expected.

    I found this by recreating your failure and searching the VHD update by the configuration for Pending.mof (dir F:\pending.mof -Recurse) and saw that the folder wasn't actually the DSC configuration folder.