Назад | Перейти на главную страницу

Можно ли указать имя компьютера в Unattend.xml с помощью скрипта?

Мне сказали, что можно запустить Powershell прямо из файла Unattend.xml во время установки ОС.

Я пытаюсь установить для 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" в качестве приветствия Мэри.

Любая помощь будет оценена

Я получил это, работая с Windows 10 pro. Примечание: синхронные команды на этапе Specialize появляются для запуска ПЕРЕД другие разделы на том же этапе. Поэтому, если у вас есть имя ПК, указанное в политике именования клиентов WDS, а xml настроен на переименование, вы столкнетесь с этой проблемой.

ProTip (После развертывания перейдите в C: \ windows \ panther \ UnattendGC \ setupact.log, чтобы просмотреть, что и когда было обработано.)

Я рекомендую запустить переименование компьютера на этапе oobe.

Также команды, которые должны быть выполнены, имеют максимальную длину ~ 250 символов. Он говорит ~ 1000, но я пробовал использовать команды PowerShell, которые были ~ 500 символов, и они не работают.

Короче говоря, попробуйте эту команду на этапе 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, которая у меня сработала. Если вы заботитесь о безопасности, создайте учетную запись для присоединения к домену wds только для этой цели, которая управляет определенными компьютерными объектами OU (для этого есть руководства), и просто измените пароль для своей учетной записи службы присоединения к домену после массового развертывания. Вы можете быстро обновить пароль в 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>