Public/Initialize-OSDBuilder.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
function Initialize-OSDBuilder {
    [CmdletBinding()]
    Param (
        #Sets the OSDBuilder Path in the Registry
        [string]$SetHome
    )
    #===================================================================================================
    # GetOSDBuilderHome
    #===================================================================================================
    if (! (Test-Path HKCU:\Software\OSDeploy)) {
        Try {New-Item HKCU:\Software -Name OSDeploy -Force | Out-Null}
        Catch {Write-Warning 'Unable to New-Item HKCU:\Software\OSDeploy'; Break}
    }

    if (Get-ItemProperty -Path 'HKCU:\Software\OSDeploy' -Name OSBuilderPath -ErrorAction SilentlyContinue) {
        Try {Rename-ItemProperty -Path 'HKCU:\Software\OSDeploy' -Name OSBuilderPath -NewName GetOSDBuilderHome -Force | Out-Null}
        Catch {Write-Warning 'Unable to Rename-ItemProperty HKCU:\Software\OSDeploy OSBuilderPath to GetOSDBuilderHome'; Break}
    }

    if (! (Get-ItemProperty -Path HKCU:\Software\OSDeploy -Name GetOSDBuilderHome -ErrorAction SilentlyContinue)) {
        Try {New-ItemProperty -Path HKCU:\Software\OSDeploy -Name GetOSDBuilderHome -Force | Out-Null}
        Catch {Write-Warning 'Unable to New-ItemProperty HKCU:\Software\OSDeploy GetOSDBuilderHome'; Break}
    }

    if ($SetHome) {
        Try {Set-ItemProperty -Path HKCU:\Software\OSDeploy -Name GetOSDBuilderHome -Value $SetHome -Force}
        Catch {Write-Warning "Unable to Set-ItemProperty HKCU:\Software\OSDeploy GetOSDBuilderHome to $SetHome"; Break}
    }

    $global:GetOSDBuilderHome = $(Get-ItemProperty "HKCU:\Software\OSDeploy").GetOSDBuilderHome
    if ($null -eq $global:GetOSDBuilderHome) {$global:GetOSDBuilderHome = "$env:SystemDrive\OSDBuilder"}
    #===================================================================================================
    # Initialize OSDBuilder Variables
    #===================================================================================================
    Write-Verbose "Initializing OSDBuilder ..." -Verbose

    
    $global:GetOSDBuilder = [ordered]@{
        Home                    = $global:GetOSDBuilderHome
        Initialize              = $true
        JsonLocal               = Join-Path $global:GetOSDBuilderHome 'OSDBuilder.json'
        JsonGlobal              = Join-Path $env:ProgramData 'OSDeploy\OSDBuilder.json'
<# PathContentADK = Join-Path $global:GetOSDBuilderHome 'Content\ADK'
        PathContentDaRT = Join-Path $global:GetOSDBuilderHome 'Content\DaRT'
        PathContentDrivers = Join-Path $global:GetOSDBuilderHome 'Content\Drivers'
        PathContentExtraFiles = Join-Path $global:GetOSDBuilderHome 'Content\ExtraFiles'
        PathContentIsoExtract = Join-Path $global:GetOSDBuilderHome 'Content\IsoExtract'
        PathContentOneDrive = Join-Path $global:GetOSDBuilderHome 'Content\OneDrive'
        PathContentPackages = Join-Path $global:GetOSDBuilderHome 'Content\Packages'
        PathContentScripts = Join-Path $global:GetOSDBuilderHome 'Content\Scripts'
        PathContentStartLayout = Join-Path $global:GetOSDBuilderHome 'Content\StartLayout'
        PathContentUnattend = Join-Path $global:GetOSDBuilderHome 'Content\Unattend' #>

    }

    $global:SetOSDBuilder = [ordered]@{
        AllowContentPacks       = $true
        AllowGlobalOptions      = $true
        #AllowLocalPriority = $false
        PathContent             = Join-Path $global:GetOSDBuilderHome 'Content'
        PathContentPacks        = Join-Path $global:GetOSDBuilderHome 'ContentPacks'
        PathFeatureUpdates        = Join-Path $global:GetOSDBuilderHome 'FeatureUpdates'
        PathMount               = Join-Path $global:GetOSDBuilderHome 'Mount'
        PathOSBuilds            = Join-Path $global:GetOSDBuilderHome 'OSBuilds'
        PathOSImport            = Join-Path $global:GetOSDBuilderHome 'OSImport'
        PathOSMedia             = Join-Path $global:GetOSDBuilderHome 'OSMedia'
        PathPEBuilds            = Join-Path $global:GetOSDBuilderHome 'PEBuilds'
        PathTasks               = Join-Path $global:GetOSDBuilderHome 'Tasks'
        PathTemplates           = Join-Path $global:GetOSDBuilderHome 'Templates'
        PathUpdates             = Join-Path $global:GetOSDBuilderHome 'Updates'

        #Get-DownOSDBuilder
        #Get-OSBuilds
        #Get-OSDBuilder
        #Get-OSMedia
        #Get-PEBuilds
        #Import-OSMedia
        ImportOSMediaAllowUnsupporteOS = $false
        ImportOSMediaBuildNetFX = $false
        ImportOSMediaEditionId = $null
        ImportOSMediaImageIndex = $null
        ImportOSMediaImageName = $null
        ImportOSMediaShowInfo = $false
        ImportOSMediaSkipGrid = $false
        ImportOSMediaSkipFeatureUpdates = $false
        ImportOSMediaUpdate = $false
        #Initialize-OSDBuilder
        #New-OSBuild
        NewOSBuildByTaskName = $null
        NewOSBuildCreateISO = $false
        NewOSBuildDontUseNewestMedia = $false
        NewOSBuildDownload = $false
        NewOSBuildExecute = $false
        NewOSBuildEnableNetFX = $false
        NewOSBuildHideCleanupProgress = $false
        NewOSBuildPauseDismountOS = $false
        NewOSBuildPauseDismountPE = $false
        NewOSBuildSelectContentPacks = $false
        NewOSBuildSelectUpdates = $false
        NewOSBuildShowHiddenOSMedia = $false
        NewOSBuildSkipComponentCleanup = $false
        NewOSBuildSkipContentPacks = $false
        NewOSBuildSkipTask = $false
        NewOSBuildSkipTemplates = $false
        NewOSBuildSkipUpdates = $false
        #New-OSBuildMultiLang
        #New-OSBuildTask
        NewOSBuildTaskAddContentPacks = $false
        NewOSBuildTaskContentDrivers = $false
        NewOSBuildTaskContentExtraFiles = $false
        NewOSBuildTaskContentFeaturesOnDemand = $false
        NewOSBuildTaskContentLanguagePackages = $false
        NewOSBuildTaskContentPackages = $false
        NewOSBuildTaskContentScripts = $false
        NewOSBuildTaskContentStartLayout = $false
        NewOSBuildTaskContentUnattend = $false
        NewOSBuildTaskContentWinPEADK = $false
        NewOSBuildTaskContentWinPEDart = $false
        NewOSBuildTaskContentWinPEDrivers = $false
        NewOSBuildTaskContentWinPEExtraFiles = $false
        NewOSBuildTaskContentWinPEScripts = $false
        NewOSBuildTaskCustomName = $null
        NewOSBuildTaskDisableFeature = $false
        NewOSBuildTaskEnableFeature = $false
        NewOSBuildTaskEnableNetFX3 = $false
        NewOSBuildTaskRemoveAppx = $false
        NewOSBuildTaskRemoveCapability = $false
        NewOSBuildTaskRemovePackage = $false
        NewOSBuildTaskTaskName = $null
        NewOSBuildTaskWinPEAutoExtraFiles = $false
        #New-OSDBuilderContentPack
        #New-OSDBuilderISO
        #New-OSDBuilderUSB
        #New-OSDBuilderVHD
        #New-PEBuild
        NewPEBuildCreateISO = $false
        NewPEBuildExecute = $false
        NewPEBuildPauseDismount = $false
        NewPEBuildPauseMount = $false
        #New-PEBuildTask
        #Show-OSDBuilderInfo
        #Update-OSMedia
        UpdateOSMediaCreateISO = $false
        UpdateOSMediaDownload = $false
        UpdateOSMediaExecute = $false
        UpdateOSMediaHideCleanupProgress = $false
        UpdateOSMediaName = $null
        UpdateOSMediaPauseDismountOS = $false
        UpdateOSMediaPauseDismountPE = $false
        UpdateOSMediaSelectUpdates = $false
        UpdateOSMediaShowHiddenOSMedia = $false
        UpdateOSMediaSkipComponentCleanup = $false
        UpdateOSMediaSkipUpdates = $false
    }
    #===================================================================================================
    # Import Local JSON
    #===================================================================================================
    if (Test-Path $global:GetOSDBuilder.JsonLocal) {
        Write-Verbose "Importing OSDBuilder Local Settings $($global:GetOSDBuilder.JsonLocal)"
        Try {
            $global:GetOSDBuilder.LocalSettings = (Get-Content $global:GetOSDBuilder.JsonLocal -RAW | ConvertFrom-Json).PSObject.Properties | foreach {[ordered]@{Name = $_.Name; Value = $_.Value}} | ConvertTo-Json | ConvertFrom-Json
            $global:GetOSDBuilder.LocalSettings | foreach {
                Write-Verbose "$($_.Name) = $($_.Value)"
                $global:SetOSDBuilder.$($_.Name) = $($_.Value)
            }
        }
        Catch {Write-Warning "Unable to import $($global:GetOSDBuilder.JsonLocal)"}
    }

    if ($global:SetOSDBuilder.AllowGlobalOptions -eq $true) {
        if (Test-Path $global:GetOSDBuilder.JsonGlobal) {
            Write-Verbose "Importing OSDBuilder Global Settings $($global:GetOSDBuilder.JsonGlobal)"
            Try {
                $global:GetOSDBuilder.GlobalSettings = (Get-Content $global:GetOSDBuilder.JsonGlobal -RAW | ConvertFrom-Json).PSObject.Properties | foreach {[ordered]@{Name = $_.Name; Value = $_.Value}} | ConvertTo-Json | ConvertFrom-Json
                $global:GetOSDBuilder.GlobalSettings | foreach {
                    Write-Verbose "$($_.Name) = $($_.Value)"
                    $global:SetOSDBuilder.$($_.Name) = $($_.Value)
                }
            }
            Catch {Write-Warning "Unable to import $($global:GetOSDBuilder.JsonGlobal)"}
        }
    }

<# if ($global:SetOSDBuilder.AllowLocalPriority -eq $true) {
        if (Test-Path $global:GetOSDBuilder.JsonLocal) {
            Write-Verbose "Importing OSDBuilder Local Priority $($global:GetOSDBuilder.JsonLocal) as Priority"
            Try {
                $global:GetOSDBuilder.LocalSettings = (Get-Content $global:GetOSDBuilder.JsonLocal -RAW | ConvertFrom-Json).PSObject.Properties | foreach {[ordered]@{Name = $_.Name; Value = $_.Value}} | ConvertTo-Json | ConvertFrom-Json
                $global:GetOSDBuilder.LocalSettings | foreach {
                    Write-Verbose "$($_.Name) = $($_.Value)"
                    $global:SetOSDBuilder.$($_.Name) = $($_.Value)
                }
            }
            Catch {Write-Warning "Unable to import $($global:GetOSDBuilder.JsonLocal)"}
        }
    } #>


    #===================================================================================================
    # Set Content Paths
    #===================================================================================================
    $global:GetOSDBuilder.PathContentADK            = Join-Path $global:SetOSDBuilder.PathContent 'ADK'
    $global:GetOSDBuilder.PathContentDaRT           = Join-Path $global:SetOSDBuilder.PathContent 'DaRT'
    $global:GetOSDBuilder.PathContentDrivers        = Join-Path $global:SetOSDBuilder.PathContent 'Drivers'
    $global:GetOSDBuilder.PathContentExtraFiles     = Join-Path $global:SetOSDBuilder.PathContent 'ExtraFiles'
    $global:GetOSDBuilder.PathContentIsoExtract     = Join-Path $global:SetOSDBuilder.PathContent 'IsoExtract'
    $global:GetOSDBuilder.PathContentOneDrive       = Join-Path $global:SetOSDBuilder.PathContent 'OneDrive'
    $global:GetOSDBuilder.PathContentPackages       = Join-Path $global:SetOSDBuilder.PathContent 'Packages'
    $global:GetOSDBuilder.PathContentScripts        = Join-Path $global:SetOSDBuilder.PathContent 'Scripts'
    $global:GetOSDBuilder.PathContentStartLayout    = Join-Path $global:SetOSDBuilder.PathContent 'StartLayout'
    $global:GetOSDBuilder.PathContentUnattend       = Join-Path $global:SetOSDBuilder.PathContent 'Unattend'
    #===================================================================================================
    # Get Variables
    #===================================================================================================
    $global:GetOSDBuilderHome                   = $global:GetOSDBuilder.Home
    $global:GetOSDBuilderPathContentADK         = $global:GetOSDBuilder.PathContentADK
    $global:GetOSDBuilderPathContentDaRT        = $global:GetOSDBuilder.PathContentDaRT
    $global:GetOSDBuilderPathContentDrivers     = $global:GetOSDBuilder.PathContentDrivers
    $global:GetOSDBuilderPathContentExtraFiles  = $global:GetOSDBuilder.PathContentExtraFiles
    $global:GetOSDBuilderPathContentIsoExtract  = $global:GetOSDBuilder.PathContentIsoExtract
    $global:GetOSDBuilderPathContentOneDrive    = $global:GetOSDBuilder.PathContentOneDrive
    $global:GetOSDBuilderPathContentPackages    = $global:GetOSDBuilder.PathContentPackages
    $global:GetOSDBuilderPathContentScripts     = $global:GetOSDBuilder.PathContentScripts
    $global:GetOSDBuilderPathContentStartLayout = $global:GetOSDBuilder.PathContentStartLayout
    $global:GetOSDBuilderPathContentUnattend    = $global:GetOSDBuilder.PathContentUnattend
    #===================================================================================================
    # Set Variables
    #===================================================================================================
    $global:SetOSDBuilderPathContent            = $global:SetOSDBuilder.PathContent
    $global:SetOSDBuilderPathContentPacks       = $global:SetOSDBuilder.PathContentPacks
    $global:SetOSDBuilderPathMount              = $global:SetOSDBuilder.PathMount
    $global:SetOSDBuilderPathOSBuilds           = $global:SetOSDBuilder.PathOSBuilds
    $global:SetOSDBuilderPathFeatureUpdates        = $global:SetOSDBuilder.PathFeatureUpdates
    $global:SetOSDBuilderPathOSImport           = $global:SetOSDBuilder.PathOSImport
    $global:SetOSDBuilderPathOSMedia            = $global:SetOSDBuilder.PathOSMedia
    $global:SetOSDBuilderPathPEBuilds           = $global:SetOSDBuilder.PathPEBuilds
    $global:SetOSDBuilderPathTasks              = $global:SetOSDBuilder.PathTasks
    $global:SetOSDBuilderPathTemplates          = $global:SetOSDBuilder.PathTemplates
    $global:SetOSDBuilderPathUpdates            = $global:SetOSDBuilder.PathUpdates
    #===================================================================================================
    # Corrections
    #===================================================================================================
    if (Test-Path "$GetOSDBuilderHome\Media") {
        Write-Warning "Renaming $GetOSDBuilderHome\Media to $SetOSDBuilderPathFeatureUpdates"
        Rename-Item "$GetOSDBuilderHome\Media" "$SetOSDBuilderPathFeatureUpdates" -Force | Out-Null
    }
    if (Test-Path "$GetOSDBuilderHome\OSDownload") {
        Write-Warning "Renaming $GetOSDBuilderHome\OSDownload to $SetOSDBuilderPathFeatureUpdates"
        Rename-Item "$GetOSDBuilderHome\OSDownload" "$SetOSDBuilderPathFeatureUpdates" -Force | Out-Null
    }
    if (Test-Path "$SetOSDBuilderPathContent\OSDUpdate") {
        Write-Warning "Moving $SetOSDBuilderPathContent\OSDUpdate to $SetOSDBuilderPathUpdates"
        if (! (Test-Path $SetOSDBuilderPathUpdates)) {New-Item $SetOSDBuilderPathUpdates -ItemType Directory -Force | Out-Null}
        Move-Item -Path "$SetOSDBuilderPathContent\OSDUpdate\*" -Destination $SetOSDBuilderPathUpdates -Force -ErrorAction SilentlyContinue | Out-Null
        Remove-Item "$SetOSDBuilderPathContent\OSDUpdate" -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
    }
    if (Test-Path "$SetOSDBuilderPathContent\Mount") {
        Write-Warning "$SetOSDBuilderPathContent\Mount has been moved to $SetOSDBuilderPathMount"
        Write-Warning "Verify that you don't have any active mounted images and remove this directory"
    }
}