PowerShell Scripts in Windows Unattend Answer File XML

9,793
2018-07-23 10:38:29, Error                        [setup.exe] SMI data results dump: Source = Name: Microsoft-Windows-Deployment, Language: neutral, ProcessorArchitecture: amd64, PublicKeyToken: 31bf3856ad364e35, VersionScope: nonSxS, /settings/FirstLogonCommands

2018-07-23 10:38:29, Error                        [setup.exe] SMI data results dump: Description = Setting is not defined in this component.

Windows setup indicates you have put the "FirstLogonCommands" block in the wrong pass in the unnattend file.

You're using two different structures for running a command. You're using "RunSynchronousCommand" and "SynchronousCommand".

First, you should be using Windows System Image Manager to create unattend files. This will insure they are formatted correctly.

The problem here is that you are using the "RunSynchronousCommand" block which works during the specialize pass, or auditUser pass. It is supposed to be contained within a "RunSynchronous" block.

You've put in a "SynchronousCommand" block which runs during the oobeSystem pass after the first user logs on to the system. But, you've put it in the specialize pass.

The RunSynchronousCommand block has to be contained in a "RunSynchronous" block and located in the Specialize or auditUser pass. The SynchronousCommand block can only be located in the oobeSystem pass. For an explanation of Windows Setup Configuration Passes and when they run see here: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-setup-configuration-passes

You need to make a decision when you want these commands to run and then properly format the unattend file by placing the commands in the proper locations. Again, Windows System Image Manager would not have validated this file.

Most likely, you want to use only "SynchronousCommand" during the oobeSystem pass. However, be aware, that Windows 10 does not run these commands synchronously. Windows will NOT wait for these commands to finish before logging the user on, contrary to what Microsoft has specified in documentation. This is new for Windows 10.

Share:
9,793

Related videos on Youtube

ztmcoder
Author by

ztmcoder

Updated on September 18, 2022

Comments

  • ztmcoder
    ztmcoder over 1 year

    So I have a Windows 10 Unattend Answer File. I got the parts where it skips the OOBE screens, enables admin account, and copy profile. I am trying to set the answer file to run a PowerShell script to import the start menu from a xml file I made from a export of the start menu. The file is located on the C drive of the image, and the path is verified.

    However when I add this Powershell command in to the answer file and run sysprep and reboot I get the following error upon Setting Up Windows: 'Windows could not parse or process unattend answer file C:\Windows\Panther\unattend.xml to pass [specialize]. A component or setting specified in the answer file does not exist.'

    Here is the problematic unattend.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <unattend xmlns="urn:schemas-microsoft-com:unattend">
        <settings pass="specialize">
            <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <AutoLogon>
                    <Password>
                        <Value>P@ssword</Value>
                        <PlainText>true</PlainText>
                    </Password>
                    <Username>Administrator</Username>
                    <Enabled>true</Enabled>
                    <LogonCount>5</LogonCount>
                </AutoLogon>
                <StartTiles>
                    <PromoteOEMTiles>false</PromoteOEMTiles>
                </StartTiles>
                <WindowsFeatures>
                    <ShowInternetExplorer>true</ShowInternetExplorer>
                    <ShowMediaCenter>false</ShowMediaCenter>
                    <ShowWindowsMail>false</ShowWindowsMail>
                    <ShowWindowsMediaPlayer>true</ShowWindowsMediaPlayer>
                </WindowsFeatures>
                <CopyProfile>true</CopyProfile>
                <DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet>
            </component>
            <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <FirstLogonCommands>
    
                    <RunSynchronousCommand wcm:action="add">
                        <Description>Set Powershell Execution Policy to Unrestricted</Description>
                        <Path>powershell.exe Set-ExecutionPolicy Unrestricted -force</Path>
                        <Order>3</Order>
                    </RunSynchronousCommand>
    
                    <SynchronousCommand wcm:action="add">
                        <Order>4</Order>
                        <CommandLine>powershell.exe Import-StartLayout –LayoutPath C:\Installs\StartMenu.xml –MountPath $env:SystemDrive\</CommandLine>
                        <Description>Start Menu</Description>
             </SynchronousCommand>
    
                </FirstLogonCommands>
            </component>
        </settings>
        <settings pass="oobeSystem">
            <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <OOBE>
                    <HideLocalAccountScreen>true</HideLocalAccountScreen>
                    <HideEULAPage>true</HideEULAPage>
                    <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
                    <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
                    <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
                    <SkipUserOOBE>true</SkipUserOOBE>
                    <SkipMachineOOBE>true</SkipMachineOOBE>
                </OOBE>
                <UserAccounts>
                    <AdministratorPassword>
                        <Value>P@ssword</Value>
                        <PlainText>true</PlainText>
                    </AdministratorPassword>
                </UserAccounts>
            </component>
        </settings>
        <cpi:offlineImage cpi:source="wim:c:/users/tester/desktop/win10/sources/install.wim#Windows 10 Pro" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
    </unattend>
    

    Here is my last good, working unattend.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <unattend xmlns="urn:schemas-microsoft-com:unattend">
        <settings pass="specialize">
            <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <WindowsFeatures>
                    <ShowWindowsMail>false</ShowWindowsMail>
                    <ShowInternetExplorer>true</ShowInternetExplorer>
                </WindowsFeatures>
                <CopyProfile>true</CopyProfile>
                <DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet>
                <AutoLogon>
                    <Password>
                        <Value>Password123!</Value>
                        <PlainText>true</PlainText>
                    </Password>
                    <Username>Administrator</Username>
                    <Enabled>true</Enabled>
                    <LogonCount>5</LogonCount>
                </AutoLogon>
                <UserAccounts>
                    <AdministratorPassword>
                        <Value>Password123!</Value>
                        <PlainText>true</PlainText>
                    </AdministratorPassword>
                </UserAccounts>
            </component>
        </settings>
        <settings pass="oobeSystem">
            <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <OOBE>
                    <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
                    <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
                    <SkipMachineOOBE>true</SkipMachineOOBE>
                    <SkipUserOOBE>true</SkipUserOOBE>
                    <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
                </OOBE>
                <WindowsFeatures>
                    <ShowInternetExplorer>true</ShowInternetExplorer>
                    <ShowWindowsMail>false</ShowWindowsMail>
                    <ShowWindowsMediaPlayer>true</ShowWindowsMediaPlayer>
                </WindowsFeatures>
                <BluetoothTaskbarIconEnabled>false</BluetoothTaskbarIconEnabled>
                <UserAccounts>
                    <AdministratorPassword>
                        <Value>Password123</Value>
                        <PlainText>Password123</PlainText>
                    </AdministratorPassword>
                </UserAccounts>
            </component>
        </settings>
        <cpi:offlineImage cpi:source="wim:c:/users/tester/desktop/win10/sources/install.wim#Windows 10 Pro" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
    </unattend>
    

    I have the PowerShell commands set in the unattend answer file with the tag.

    Also here is the logs that I pulled from C:\Windows\Panther after Sysprep...

    2018-07-23 10:38:29, Error                        [setup.exe] SMI data results dump: Source = Name: Microsoft-Windows-Deployment, Language: neutral, ProcessorArchitecture: amd64, PublicKeyToken: 31bf3856ad364e35, VersionScope: nonSxS, /settings/FirstLogonCommands
    
    2018-07-23 10:38:29, Error                        [setup.exe] SMI data results dump: Description = Setting is not defined in this component.
    
    
    2018-07-23 10:38:29, Error      [0x060432] IBS    The provided unattend file is not valid; hrResult = 0x80220001
    
    2018-07-23 10:38:29, Error      [0x060565] IBS    Callback_Unattend_InitEngine:The provided unattend file [C:\Windows\Panther\unattend.xml] is not a valid unattended Setup answer file; hr = 0x1, hrSearched = 0x1, hrDeserialized = 0x0, hrImplicitCtx = 0x0, hrValidated = 0x1, hrResult = 0x80220001
    
    
    2018-07-23 10:38:29, Error      [0x0600c2] IBS    Callback_Unattend_InitEngine:An error occurred while finding/loading the unattend file; hr = 0x1, hrResult = 0x80220001[gle=0x00000490]
    
    • Appleoddity
      Appleoddity almost 6 years
      This error does not indicate a problem with your powershell script. It indicates a problem with your unattend file. Please post the sanitized unattend file. In addition, relevant logs are located under c:\windows\panther if I remember correctly.
    • Appleoddity
      Appleoddity almost 6 years
      Also, don’t post your code and unattend file via link. Copy and paste it directly in to your post using code blocks.
    • ztmcoder
      ztmcoder almost 6 years
      Whatever the error is it won't let me boot into Windows so I am unable to get those logs.
    • Appleoddity
      Appleoddity almost 6 years
      Sure you can. When the error is on the screen (or most times during windows setup) you can press shift-f10 or f8 and open a command window. There you can run notepad or copy files to flash drive, etc. you could also boot in to windows setup and run a command prompt (using recovery), or another live disc of some sort.
    • ztmcoder
      ztmcoder almost 6 years
      Ok I will do that. I did try putting my code in normally to the question but I couldn't get it to format correctly, so I just put the link to it, rather than it being difficult to read because of formatting... Here is the link to the working Answer File that works. github.com/ztmurphy21/Windows-Unattend/blob/master/…
    • Appleoddity
      Appleoddity almost 6 years
      Sorry, I misunderstood your post. I thought you were running a powershell script and had linked to that. You actually linked to the unattend file. Ok, I have edited your post and added both unattend files to your post.
    • ztmcoder
      ztmcoder almost 6 years
      Ok I made some edits too, I added the errors from the C:\Windows\Panther in my original post.
  • ztmcoder
    ztmcoder almost 6 years
    So whenever I right click on the 'Windows Deployment neutral' It only lets me add it to either Specialize or audit user and not the oobeSystem, which I want to add it to the OOBE System since that is where you should have the Synchronous Command.
  • Appleoddity
    Appleoddity almost 6 years
    You're getting a little confused between these two, similarly named components. There is "RunSynchronousCommand" which is part of the "RunSynchronous" block and windows-deployment component, which is what you are trying to add to oobeSystem which is not possible. Then there is the "SynchronousCommand" under the "FirstLogonCommands" block which is part of the Windows-Shell-Setup component, which is what I'm talking about
  • ztmcoder
    ztmcoder almost 6 years
    Ok I see it now. Going to give that a try.
  • ztmcoder
    ztmcoder almost 6 years
    Doesn't seem to be erroring out now. But the start menu layout does not get applied. Would that be because of Windows not waiting for the command to finish? Also does it matter if the command requires administrator privileges?
  • ztmcoder
    ztmcoder almost 6 years
    It is working now. Had to change 'Requires User Input' to false.