@@ -38,15 +38,15 @@ function Enable-LocalSecurityPolicy {
3838. Description
3939 This cmdlet creates the Unattend file for sysprep
4040#>
41- function Create-Unattend {
41+ function Create-vSphere- Unattend {
4242 Param (
4343 [string ]$UnattendDestination = " C:\Windows\Panther\Unattend" ,
4444 [string ]$NewPassword ,
4545 [string ]$ProductKey ,
4646 [string ]$Organization ,
4747 [string ]$Owner
4848 )
49- Write-Log " Starting Create-Unattend"
49+ Write-Log " Starting Create-vSphere- Unattend"
5050
5151 New-Item - ItemType directory $UnattendDestination - Force
5252 $UnattendPath = Join-Path $UnattendDestination " unattend.xml"
@@ -151,77 +151,7 @@ function Create-Unattend {
151151 Out-File - FilePath $UnattendPath - InputObject $PostUnattend - Encoding utf8
152152}
153153
154- <#
155- . Synopsis
156- Sanity check that the unattend.xml shipped with GCP has not changed.
157- . Description
158- Sanity check that the unattend.xml shipped with GCP has not changed.
159- #>
160- function Check-Default-GCP-Unattend {
161-
162- [xml ]$Expected = @'
163- <?xml version="1.0" encoding="utf-8"?>
164- <unattend xmlns="urn:schemas-microsoft-com:unattend">
165- <!--
166- For more information about unattended.xml please refer too
167- http://technet.microsoft.com/en-us/library/cc722132(v=ws.10).aspx
168- -->
169- <settings pass="generalize">
170- <component name="Microsoft-Windows-PnpSysprep" 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">
171- <PersistAllDeviceInstalls>true</PersistAllDeviceInstalls>
172- </component>
173- </settings>
174- <settings pass="specialize">
175- <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">
176- <!-- Random ComputerName, will be replaced by specialize script -->
177- <ComputerName></ComputerName>
178- <TimeZone>Greenwich Standard Time</TimeZone>
179- </component>
180- </settings>
181- <settings pass="oobeSystem">
182- <!-- Setting Location Information -->
183- <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">
184- <InputLocale>en-us</InputLocale>
185- <SystemLocale>en-us</SystemLocale>
186- <UILanguage>en-us</UILanguage>
187- <UserLocale>en-us</UserLocale>
188- </component>
189- <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">
190- <OOBE>
191- <!-- Setting EULA -->
192- <HideEULAPage>true</HideEULAPage>
193- <!-- Setting network location to public -->
194- <NetworkLocation>Other</NetworkLocation>
195- <!-- Hide Wirelss setup -->
196- <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
197- <ProtectYourPC>1</ProtectYourPC>
198- <SkipMachineOOBE>true</SkipMachineOOBE>
199- <SkipUserOOBE>true</SkipUserOOBE>
200- </OOBE>
201- <!-- Setting timezone to GMT -->
202- <ShowWindowsLive>false</ShowWindowsLive>
203- <TimeZone>Greenwich Standard Time</TimeZone>
204- <!--Setting OEM information -->
205- <OEMInformation>
206- <Manufacturer>Google Cloud Platform</Manufacturer>
207- <Model>Google Compute Engine Virtual Machine</Model>
208- <SupportURL>https://support.google.com/enterprisehelp/answer/142244?hl=en#cloud</SupportURL>
209- <Logo>C:\Program Files\Google Compute Engine\sysprep\gcp.bmp</Logo>
210- </OEMInformation>
211- </component>
212- </settings>
213- </unattend>
214- '@
215-
216- $UnattendPath = " C:\Program Files\Google\Compute Engine\sysprep\unattended.xml"
217- [xml ]$Unattend = (Get-Content - Path $UnattendPath )
218-
219- if (-Not ($Unattend.xml.Equals ($Expected.xml ))) {
220- Write-Error " The unattend.xml shipped with GCP has changed."
221- }
222- }
223-
224- function Create-Unattend-GCP {
154+ function Create-GCP-UnattendXML {
225155 Param (
226156 [string ]$UnattendDestination = " C:\Program Files\Google\Compute Engine\sysprep"
227157 )
@@ -324,9 +254,9 @@ function Remove-UserAccounts {
324254 Write-Log " Removing UserAccounts block from Answer File"
325255
326256 $content = [xml ](Get-Content $AnswerFilePath )
327- $mswShellSetup = (($content.unattend.settings | where {$_.pass -eq ' oobeSystem' }).component| where {$_.name -eq " Microsoft-Windows-Shell-Setup" })
257+ $mswShellSetup = (($content.unattend.settings | Where-Object {$_.pass -eq ' oobeSystem' }).component| Where-Object {$_.name -eq " Microsoft-Windows-Shell-Setup" })
328258
329- if ($mswShellSetup -eq $Null ) {
259+ if ($Null -eq $mswShellSetup ) {
330260 Throw " Could not locate oobeSystem XML block. You may not be running this function on an answer file."
331261 }
332262
@@ -341,7 +271,7 @@ function Remove-UserAccounts {
341271 $content.Save ($AnswerFilePath )
342272}
343273
344- function Update-AWS2016Config
274+ function Update-AWS-LaunchConfigJSON
345275{
346276 $LaunchConfigJson = ' C:\ProgramData\Amazon\EC2-Windows\Launch\Config\LaunchConfig.json'
347277 $LaunchConfig = Get-Content $LaunchConfigJson - raw | ConvertFrom-Json
@@ -350,7 +280,7 @@ function Update-AWS2016Config
350280 $LaunchConfig | ConvertTo-Json | Set-Content $LaunchConfigJson
351281}
352282
353- function Create-Unattend- AWS
283+ function Update- AWS-UnattendedXML
354284{
355285 $UnattendedXmlPath = ' C:\ProgramData\Amazon\EC2-Windows\Launch\Sysprep\Unattend.xml'
356286 $UnattendedContent = [xml ](Get-Content $UnattendedXmlPath )
@@ -372,9 +302,9 @@ function Create-Unattend-AWS
372302 $UnattendedContent.Save ($UnattendedXmlPath )
373303}
374304
375- function Enable-AWS2016Sysprep {
305+ function Enable-AWS-Sysprep {
376306 # Enable sysprep
377- cd ' C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts'
307+ Set-Location ' C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts'
378308 ./ InitializeInstance.ps1 - Schedule
379309 ./ SysprepInstance.ps1
380310}
@@ -401,16 +331,7 @@ function Invoke-Sysprep()
401331
402332 $OsVersion = Get-OSVersion
403333
404- # WARN WARN: this should be removed when Microsoft fixes this bug
405- # See tracker story https://www.pivotaltracker.com/story/show/150238324
406- # Skip sysprep if using Windows Server 2016 insider build with UALSVC bug
407- $RegPath = " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
408- If ((Get-ItemProperty - Path $RegPath ).CurrentBuildNumber -Eq ' 16278' )
409- {
410- Stop-Computer
411- }
412-
413- Allow- NTPSync
334+ Set-NTP - Max- PhaseCorrection- Values
414335
415336 if (-Not $SkipLGPO )
416337 {
@@ -429,21 +350,21 @@ function Invoke-Sysprep()
429350 switch ($IaaS ) {
430351 " aws" {
431352 Disable-AgentService
432- Create - Unattend - AWS
433- Update-AWS2016Config
434- Enable-AWS2016Sysprep
353+ Update- AWS- LaunchConfigJSON
354+ Update-AWS - UnattendedXML
355+ Enable-AWS - Sysprep
435356 }
436357 " gcp" {
437358 Disable-AgentService
438- Create- Unattend - GCP
359+ Create- GCP- UnattendXML
439360 GCESysprep
440361 }
441362 " azure" {
442363 C:\Windows\System32\Sysprep\sysprep.exe / generalize / quiet / oobe / quit
443364 }
444365 " vsphere" {
445366 Disable-AgentService
446- Create- Unattend - NewPassword $NewPassword - ProductKey $ProductKey `
367+ Create- vSphere - Unattend - NewPassword $NewPassword - ProductKey $ProductKey `
447368 - Organization $Organization - Owner $Owner
448369
449370 Invoke-Expression - Command ' C:/windows/system32/sysprep/sysprep.exe /generalize /oobe /unattend:"C:/Windows/Panther/Unattend/unattend.xml" /quiet /shutdown'
@@ -473,7 +394,7 @@ function ModifyInfFile {
473394 Move-Item - Path $TempFile - Destination $InfFilePath - Force
474395}
475396
476- function Allow-NTPSync {
397+ function Set-NTP-Max-PhaseCorrection-Values {
477398 Set-ItemProperty - Path " HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" - Name ' MaxNegPhaseCorrection' - Value 0xFFFFFFFF - Type dword
478399 Set-ItemProperty - Path " HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" - Name ' MaxPosPhaseCorrection' - Value 0xFFFFFFFF - Type dword
479400}
0 commit comments