web-dev-qa-db-ja.com

スクリプトでUnattend.xmlにComputerNameを設定することは可能ですか?

OSのインストール中にUnattend.xmlから直接Powershellを実行することが可能であると言われました。

ComputerNameを(A + "SerialNumber")に設定しようとしていますが、ステップオーバーされ続けるファイルをどのように書き込むかは関係ありません。

現在、私は以下のXMLを持っています

<settings pass="specialize">
        <component name="Microsoft-Windows-International-Core" 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">
            <InputLocale>en-IE</InputLocale>
            <SystemLocale>en-IE</SystemLocale>
            <UILanguage>en-IE</UILanguage>
            <UserLocale>en-IE</UserLocale>
            <UILanguageFallback></UILanguageFallback>
        </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">
            <RunAsynchronous>
                <RunAsynchronousCommand wcm:action="add">
                    <Path>powershell.exe –ExecutionPolicy Bypass -File "\\server\store\Software\Powershell\UnattendedInstallComputerName.ps1"</Path>
                    <Description>Use script to rename computer with Serial number</Description>
                    <Order>1</Order>
                </RunAsynchronousCommand>
            </RunAsynchronous>
        </component>
    </settings>
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-International-Core" 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">
            <InputLocale>en-IE</InputLocale>
            <SystemLocale>en-IE</SystemLocale>
            <UILanguage>en-IE</UILanguage>
            <UserLocale>en-IE</UserLocale>
        </component>
    </settings>

スクリプトは単に次のように呼び出されます

$Serial = Get-WmiObject win32_bios | select -expand serialnumber
$CompName = "A" + $Serial
Rename-Computer $CompName

今、私はさまざまなパス実行で上記のバリアントをロードしましたが、運はありません。私は正直に、 "powershell.exe –ExecutionPolicy Bypass -File"をあられメアリーとしてスローしました。

どんな助けもいただければ幸いです

1
user001

これは、windows 10 proで動作しました。メモとして:Specializeステージの同期コマンドが実行されているようです[〜#〜] before [〜#〜]同じステージの他のセクション。したがって、WDSクライアントの名前付けポリシーでPC名が指定されており、xmlが名前変更するように構成されている場合、その問題が発生します。

ProTip(展開後、C:\ windows\panther\UnattendGC\setupact.logに移動して、何がいつ処理されたかを確認します。)

OOBEステージでPCの名前変更を実行することをお勧めします。

また、実行されるコマンドの最大長は合計で250文字までです。それは〜1000と書いてありますが、私は〜500文字のpowershellコマンドを試してみましたが、サイレントは失敗します。

つまり、oobeステージで次のコマンドを試してください:C:\ windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -noprofile -command "Start-Transcript;(Get-WmiObject win32_computersystem).Rename((Get- WmiObject 'win32_bios')。serialnumber.trim()); Stop-Transcript "

このxmlには、oobeの段階でドメインに参加するための構造も含まれていることに注意してください。セキュリティを意識している場合は、特定のOUのコンピューターオブジェクトを制御する目的でwdsドメイン参加アカウントを作成し(これに関するガイドがあります)、大規模な展開後にドメイン参加サービスアカウントのパスワードを変更します。別の一括展開操作がある場合は、xmlのパスワードをすばやく更新し、WDSサーバーに再インポートできます。

参照用XML ...

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-Microsoft-com:unattend">
    <servicing></servicing>
    <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">
            <DesktopOptimization>
                <ShowWindowsStoreAppsOnTaskbar>false</ShowWindowsStoreAppsOnTaskbar>
            </DesktopOptimization>
            <ComputerName></ComputerName>
            <CopyProfile>true</CopyProfile>
            <ShowPowerButtonOnStartScreen>true</ShowPowerButtonOnStartScreen>
            <TimeZone>US Mountain Standard Time</TimeZone>
        </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">
            <RunSynchronous>
                <RunSynchronousCommand wcm:action="add">
                    <Order>4</Order>
                    <Path>CMD /c REG.exe add HKLM\System\CurrentControlSet\Control\Network\NewNetworkWindowOff /f</Path>
                    <Description>prevent the Network location from appearing</Description>
                </RunSynchronousCommand>
            </RunSynchronous>
        </component>
        <component name="Microsoft-Windows-Security-SPP-UX" 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">
            <SkipAutoActivation>true</SkipAutoActivation>
        </component>
        <component name="Microsoft-Windows-TerminalServices-LocalSessionManager" 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">
            <fDenyTSConnections>false</fDenyTSConnections>
        </component>
        <component name="Microsoft-Windows-SQMApi" 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">
            <CEIPEnabled>0</CEIPEnabled>
        </component>
    </settings>
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-International-Core" 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">
            <InputLocale>en-US</InputLocale>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
            <UILanguageFallback>en-US</UILanguageFallback>
        </component>
        <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>
                <HideEULAPage>true</HideEULAPage>
                <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
                <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
                <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
                <NetworkLocation>Work</NetworkLocation>
                <HideLocalAccountScreen>true</HideLocalAccountScreen>
                <ProtectYourPC>3</ProtectYourPC>
                <SkipMachineOOBE>true</SkipMachineOOBE>
                <SkipUserOOBE>true</SkipUserOOBE>
                <UnattendEnableRetailDemo>false</UnattendEnableRetailDemo>
            </OOBE>
            <UserAccounts>
                <LocalAccounts>
                    <LocalAccount wcm:action="add">
                        <Password>
                            <Value>=OBVIOUSLYREPLACED...</Value>
                            <PlainText>false</PlainText>
                        </Password>
                        <Description>Admin User</Description>
                        <DisplayName>Admin User</DisplayName>
                        <Group>administrators</Group>
                        <Name>admin</Name>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <AutoLogon>
                <Password>
                    <Value>=OBVIOUSLYREPLACED...</Value>
                    <PlainText>false</PlainText>
                </Password>
                <LogonCount>5</LogonCount>
                <Enabled>true</Enabled>
                <Username>admin</Username>
            </AutoLogon>
            <DesktopOptimization>
                <ShowWindowsStoreAppsOnTaskbar>false</ShowWindowsStoreAppsOnTaskbar>
            </DesktopOptimization>
            <FirstLogonCommands>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -noprofile -command &quot;Start-Transcript;(Get-WmiObject win32_computersystem).Rename((Get-WmiObject &apos;win32_bios&apos;).serialnumber.trim());Stop-Transcript&quot;</CommandLine>
                    <Description>Rename PC to ServiceTag</Description>
                    <Order>10</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\Windows\System32\shutdown.exe /r /f /t 0</CommandLine>
                    <Description>Reboot to Rename</Description>
                    <Order>11</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>CMD /c &quot;Del C:\j.ps1 /F /Q&quot;</CommandLine>
                    <Description>Delete powershell script to join to domain</Description>
                    <Order>40</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\Windows\System32\shutdown.exe /r /f /t 0</CommandLine>
                    <Description>Reboot after Domain Join</Description>
                    <Order>48</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>CMD /c REG.exe add HKLM\System\CurrentControlSet\Control\Network\NewNetworkWindowOff /f</CommandLine>
                    <Order>1</Order>
                    <Description>prevent the Network location from appearing</Description>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <Order>21</Order>
                    <CommandLine>CMD /c &quot;Del C:\t.ps1 /F /Q&quot;</CommandLine>
                    <Description>Delete powershell script for power options</Description>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <Description>Execute script to Disable lid close action Sleep While Powered and never sleep while on AC power</Description>
                    <Order>25</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                    <CommandLine>C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoLogo -Noninteractive -File &quot;C:\t.ps1&quot;</CommandLine>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -noprofile -command &quot;Start-Transcript;(Invoke-Expression -Command $(&apos;POWERCFG /H Off&apos;) -Verbose);Stop-Transcript;&quot;</CommandLine>
                    <Description>Disable Hybernate</Description>
                    <Order>20</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\Windows\System32\gpupdate.exe /target:computer /force</CommandLine>
                    <Description>Force a GPO Update</Description>
                    <Order>50</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\Windows\System32\shutdown.exe /r /f /t 0</CommandLine>
                    <Description>Reboot to complete gpo update</Description>
                    <Order>51</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -noprofile -command &quot;Start-Transcript;Set-ItemProperty -Path &apos;HKLM:\System\CurrentControlSet\Control\Terminal Server&apos; -Name &apos;fDenyTSConnections&apos; –Value 0&quot;</CommandLine>
                    <Description>Enable RDP</Description>
                    <Order>30</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -noprofile -command &quot;Start-Transcript;Enable-NetFirewallRule -DisplayGroup &apos;Remote Desktop&apos; -verbose;Stop-Transcript&quot;</CommandLine>
                    <Description>Enable Firewall RDP Rule</Description>
                    <Order>32</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\windows\system32\cmd.exe /c &quot;Netsh advfirewall firewall set rule group=&quot;remote desktop&quot; new enable=yes&quot;</CommandLine>
                    <Description>Enable Remote Desktop Rule via cmd</Description>
                    <Order>31</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <Description>Wait and Reboot Once more After Gpupdate</Description>
                    <CommandLine>C:\Windows\System32\shutdown.exe /r /f /t 0</CommandLine>
                    <Order>55</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\Windows\System32\shutdown.exe /r /f /t 0</CommandLine>
                    <Description>Reboot once more</Description>
                    <Order>60</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <Order>22</Order>
                    <CommandLine>CMD /c &quot;echo Start-Transcript;$PSO=(Invoke-Expression -Command $(&apos;POWERCFG /GETACTIVESCHEME&apos;));[GUID]$CPD=$PSO.split(&apos;:&apos;)[1].split(&apos;(&apos;)[0].trim() &gt;&gt; C:\t.ps1&quot;</CommandLine>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>CMD /c &quot;echo [GUID]$SSG=&apos;4f971e89-eebd-4455-a8de-9e59040e7347&apos;;[GUID]$SAS=&apos;5ca83367-6e45-459f-a27b-476b1d01c936&apos;;$SDS=000;(Invoke-Expression -Command $(&quot;POWERCFG /SETACVALUEINDEX $CPD $SSG $SAS $SDS&quot;) -Verbose) &gt;&gt; C:\t.ps1&quot;</CommandLine>
                    <Order>23</Order>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>CMD /c &quot;echo [GUID]$SSG=&apos;238c9fa8-0aad-41ed-83f4-97be242c8f20&apos;;[GUID]$SAS=&apos;29f6c1db-86da-48c5-9fdb-f2b67b1f44da&apos;;$SDS=000;(Invoke-Expression -Command $(&quot;POWERCFG /SETACVALUEINDEX $CPD $SSG $SAS $SDS&quot;) -Verbose);Stop-Transcript &gt;&gt; C:\t.ps1&quot;</CommandLine>
                    <Order>24</Order>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <Order>41</Order>
                    <CommandLine>CMD /c &quot;echo Start-Transcript;Write-Host &apos;Waiting 20 seconds for Network...&apos;;Start-Sleep -seconds 20 &gt;&gt; C:\j.ps1&quot;</CommandLine>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>CMD /c &quot;echo $Cred = $(New-Object -Type &apos;PSCredential&apos; -Arg &apos;MYDOMAIN.COM\WDSDomainJoinAccount&apos;,$(ConvertTo-SecureString &apos;=OBVIOUSLYREPLACED...&apos; -AsPlain -Force)) &gt;&gt; C:\j.ps1&quot;</CommandLine>
                    <Order>42</Order>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>CMD /c &quot;echo $OU = &apos;OU=Windows Deployment Machines,OU=SBSComputers,OU=Computers,OU=MyBusiness,DC=MYDOMAIN.COM,DC=local&apos; &gt;&gt; C:\j.ps1&quot;</CommandLine>
                    <Order>43</Order>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>CMD /c &quot;echo Add-Computer -Domain &apos;MYDOMAIN.COM.local&apos; -Cred $Cred -OU $OU -Force -Verbose;Stop-Transcript &gt;&gt; C:\j.ps1&quot;</CommandLine>
                    <Order>44</Order>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoLogo -Noninteractive -File &quot;C:\j.ps1&quot;</CommandLine>
                    <Order>45</Order>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>CMD /C &quot;Del C:\*.ps1 /f /q&quot;</CommandLine>
                    <Description>Remove powershell scripts</Description>
                    <Order>70</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                </SynchronousCommand>
            </FirstLogonCommands>
            <WindowsFeatures>
                <ShowInternetExplorer>true</ShowInternetExplorer>
            </WindowsFeatures>
        </component>
    </settings>
    <settings pass="windowsPE">
        <component name="Microsoft-Windows-International-Core-WinPE" 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">
            <SetupUILanguage>
                <UILanguage>en-US</UILanguage>
            </SetupUILanguage>
            <InputLocale>en-US</InputLocale>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
            <UILanguageFallback>en-US</UILanguageFallback>
        </component>
        <component name="Microsoft-Windows-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">
            <DiskConfiguration>
                <WillShowUI>OnError</WillShowUI>
                <Disk wcm:action="add">
                    <CreatePartitions>
                        <CreatePartition wcm:action="add">
                            <Order>1</Order>
                            <Size>500</Size>
                            <Type>Primary</Type>
                        </CreatePartition>
                        <CreatePartition wcm:action="add">
                            <Order>2</Order>
                            <Type>EFI</Type>
                            <Extend>false</Extend>
                            <Size>100</Size>
                        </CreatePartition>
                        <CreatePartition wcm:action="add">
                            <Order>3</Order>
                            <Size>16</Size>
                            <Type>MSR</Type>
                        </CreatePartition>
                        <CreatePartition wcm:action="add">
                            <Extend>true</Extend>
                            <Order>4</Order>
                            <Type>Primary</Type>
                        </CreatePartition>
                    </CreatePartitions>
                    <ModifyPartitions>
                        <ModifyPartition wcm:action="add">
                            <Format>NTFS</Format>
                            <Label>WinRE</Label>
                            <Order>1</Order>
                            <PartitionID>1</PartitionID>
                            <TypeID>DE94BBA4-06D1-4D40-A16A-BFD50179D6AC</TypeID>
                        </ModifyPartition>
                        <ModifyPartition wcm:action="add">
                            <Format>FAT32</Format>
                            <Order>2</Order>
                            <PartitionID>2</PartitionID>
                            <Label>System</Label>
                        </ModifyPartition>
                        <ModifyPartition wcm:action="add">
                            <Order>3</Order>
                            <PartitionID>3</PartitionID>
                        </ModifyPartition>
                        <ModifyPartition wcm:action="add">
                            <PartitionID>4</PartitionID>
                            <Order>4</Order>
                            <Letter>C</Letter>
                            <Label>Windows</Label>
                            <Format>NTFS</Format>
                        </ModifyPartition>
                    </ModifyPartitions>
                    <DiskID>0</DiskID>
                    <WillWipeDisk>true</WillWipeDisk>
                </Disk>
            </DiskConfiguration>
            <ImageInstall>
                <OSImage>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>4</PartitionID>
                    </InstallTo>
                </OSImage>
            </ImageInstall>
            <UserData>
                <ProductKey>
                    <Key>VK7JG-NPHTM-C97JM-9MPGT-3V66T</Key>
                </ProductKey>
                <AcceptEula>true</AcceptEula>
            </UserData>
            <WindowsDeploymentServices>
                <Login>
                    <Credentials>
                        <Domain>MYDOMAIN.COM.local</Domain>
                        <Username>WDSServiceAccount</Username>
                        <Password>23473wtusjuwe6wsths</Password>
                    </Credentials>
                </Login>
                <ImageSelection>
                    <InstallImage>
                        <Filename>Windows 10 Pro Dell.wim</Filename>
                        <ImageGroup>Windows10</ImageGroup>
                        <ImageName>Windows 10 Pro Dell</ImageName>
                    </InstallImage>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>4</PartitionID>
                    </InstallTo>
                </ImageSelection>
            </WindowsDeploymentServices>
        </component>
    </settings>
    <cpi:offlineImage cpi:source="catalog:c:/users/=OBVIOUSLYREPLACED.../desktop/windows sim catalog files/install_windows 10 pro.clg" xmlns:cpi="urn:schemas-Microsoft-com:cpi" />
</unattend>
1
Herbert Origas