Files/DEV/Use-WindowsUnattend.autopilotoobehash.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function Use-WindowsUnattend.autopilotoobehash {
    [CmdletBinding()]
    param ()
$SpecializeCmd = @'
@echo on
 
REM Set OOBE Startup
reg add HKLM\SYSTEM\Setup /v CmdLine /d "PowerShell -ExecutionPolicy Bypass -Command Start-OSDCloud.windeploy.oobe" /F
 
REM Starting Specialize Phase
%WinDir%\System32\oobe\windeploy.exe
 
REM Set OOBE Startup
reg add HKLM\SYSTEM\Setup /v CmdLine /d "PowerShell -ExecutionPolicy Bypass -Command Start-OSDCloud.windeploy.oobe" /F
'@


$UnattendXml = @'
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="specialize">
<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>1</Order>
    <Description>OSDCloud</Description>
    <Path>C:\Windows\Setup\Scripts\Specialize.cmd</Path>
    </RunSynchronousCommand>
 
</RunSynchronous>
</component>
</settings>
</unattend>
'@


    #=================================================
    # Block
    #=================================================
    Block-WinOS
    Block-WindowsVersionNe10
    Block-PowerShellVersionLt5
    #=================================================
    # Setup Scripts Specialize.cmd
    #=================================================
    $SetupScripts = 'C:\Windows\Setup\Scripts'
    if (-NOT (Test-Path $SetupScripts)) {
        New-Item -Path $SetupScripts -ItemType Directory -Force | Out-Null
    }

    $SpecializeCmdPath = "C:\Windows\Setup\Scripts\Specialize.cmd"
    Write-Verbose -Verbose "Setting OSDCloud Specialize.cmd at $SpecializeCmdPath"
    $SpecializeCmd | Out-File -FilePath $SpecializeCmdPath -Width 2000 -Force
    #=================================================
    # Panther Unattend.xml
    #=================================================
    $Panther = 'C:\Windows\Panther'
    if (-NOT (Test-Path $Panther)) {
        New-Item -Path $Panther -ItemType Directory -Force | Out-Null
    }

    $UnattendPath = "$Panther\Unattend.xml"
    Write-Verbose -Verbose "Setting OSDCloud Unattend.xml at $UnattendPath"
    $UnattendXml | Out-File -FilePath $UnattendPath -Encoding utf8 -Width 2000 -Force
    #=================================================
    # Use-WindowsUnattend
    #=================================================
    Write-Verbose -Verbose "Use-WindowsUnattend -Path 'C:\' -UnattendPath $UnattendPath"
    Use-WindowsUnattend -Path 'C:\' -UnattendPath $UnattendPath -Verbose
    
    Write-Verbose -Verbose "Copy-PSModuleToFolder -Name OSD to C:\Program Files\WindowsPowerShell\Modules"
    Copy-PSModuleToFolder -Name OSD -Destination 'C:\Program Files\WindowsPowerShell\Modules'

    reg load HKLM\OfflineSystem C:\Windows\System32\Config\SYSTEM
    reg add HKLM\OfflineSystem\Setup /v CmdLine /d "C:\Windows\Setup\Scripts\Specialize.cmd" /F
    reg unload HKLM\OfflineSystem

    Notepad $UnattendPath
    #=================================================
}