Public/Get-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 |
<#
.SYNOPSIS Offline Servicing for Windows 10, Windows 11, Server 2019, and Server 2022 .DESCRIPTION Offline Servicing for Windows 10, Windows 11, Server 2019, and Server 2022 .LINK https://osdbuilder.osdeploy.com/module/functions/get-osdbuilder #> function Get-OSDBuilder { [CmdletBinding()] param ( #Creates OSDBuilder directory structure #Directories are automatically created with first Import #Alias: Create [Alias('Create')] [switch]$CreatePaths, #Quick Download options [ValidateSet('FeatureUpdates','OneDrive','OneDriveEnterprise','OSMediaUpdates')] [string]$Download, #Initializes OSDBuilder variables #This action will occur automatically if OSDBuilder variables are not set [switch]$Initialize, #Hides Write-Host output. Used when called from other functions #Alias: Silent [Alias('Silent')] [switch]$HideDetails, #Quick options [ValidateSet('OneDrive','Download','Cleanup')] [string]$Quick, #Changes the path from the default of C:\OSDBuilder to the path specified #Alias: Path [Alias('Path','SetPath')] [ValidateNotNullOrEmpty()] [string]$SetHome, #Updates the OSDBuilder Module #Alias: Update [Alias('Update')] [switch]$UpdateModule ) #================================================= # Initialize-OSDBuilder #================================================= #Must initialize the OSDBuilder variables. This will set all to defaults #If Home is not set, then we need to initialize as well if ($SetHome) {Initialize-OSDBuilder -SetHome $SetHome} elseif (($Initialize.IsPresent) -or (!($global:GetOSDBuilder.Home))) {Initialize-OSDBuilder} if (($(Get-ItemProperty "HKCU:\Software\OSDeploy").GetOSDBuilderHome) -ne $global:GetOSDBuilderHome) {Initialize-OSDBuilder} #================================================= # OSDBuilder.PSModule* #================================================= $global:GetOSDBuilder.PSModuleOSD = Get-Module -Name OSD | Select-Object * $global:GetOSDBuilder.PSModuleOSDBuilder = Get-Module -Name OSDBuilder | Select-Object * #================================================= # OSDBuilder.Public* #================================================= $global:GetOSDBuilder.PublicJson = $null #$global:GetOSDBuilder.PublicJsonURL = "https://raw.githubusercontent.com/OSDeploy/OSDBuilder.Public/master/OSDBuilder.json" $global:GetOSDBuilder.PublicJsonURL = "https://raw.githubusercontent.com/OSDeploy/OSD.Public/master/OSD.json" #================================================= # OSDBuilder.Version* #================================================= $global:GetOSDBuilder.VersionOSD = $global:GetOSDBuilder.PSModuleOSD.Version | Sort-Object | Select-Object -Last 1 $global:GetOSDBuilder.VersionOSDPublic = $global:GetOSDBuilder.VersionOSD $global:GetOSDBuilder.VersionOSDBuilder = $global:GetOSDBuilder.PSModuleOSDBuilder.Version | Sort-Object | Select-Object -Last 1 $global:GetOSDBuilder.VersionOSDBuilderPublic = $global:GetOSDBuilder.VersionOSDBuilder if (!($HideDetails.IsPresent)) { $StatusCode = try {(Invoke-WebRequest -Uri $global:GetOSDBuilder.PublicJsonURL -UseBasicParsing -DisableKeepAlive).StatusCode} catch [Net.WebException]{[int]$_.Exception.Response.StatusCode} if ($StatusCode -ne "200") { #Check Failed } else { $global:GetOSDBuilder.PublicJson = Invoke-RestMethod -Uri $global:GetOSDBuilder.PublicJsonURL $global:GetOSDBuilder.VersionOSDPublic = $global:GetOSDBuilder.PublicJson.OSD $global:GetOSDBuilder.VersionOSDBuilderPublic = $global:GetOSDBuilder.PublicJson.OSDBuilder } } #================================================= # Display Version Information #================================================= if (!($HideDetails.IsPresent)) { if ($null -eq $global:GetOSDBuilder.PublicJson) { Write-Verbose "OSDBuilder $($global:GetOSDBuilder.VersionOSDBuilder) | OSD $($global:GetOSDBuilder.VersionOSD) | OFFLINE" -Verbose } else { if ($global:GetOSDBuilder.VersionOSDBuilder -ge $global:GetOSDBuilder.VersionOSDBuilderPublic) { Write-Host "OSDBuilder $($global:GetOSDBuilder.VersionOSDBuilder) " -ForegroundColor Green -NoNewline } else { Write-Host "OSDBuilder $($global:GetOSDBuilder.VersionOSDBuilder) " -ForegroundColor Yellow -NoNewline } Write-Host "| " -ForegroundColor White -NoNewline if ($global:GetOSDBuilder.VersionOSD -ge $global:GetOSDBuilder.VersionOSDPublic) { Write-Host "OSD $($global:GetOSDBuilder.VersionOSD) " -ForegroundColor Green } else { Write-Host "OSD $($global:GetOSDBuilder.VersionOSD) " -ForegroundColor Yellow } } } #================================================= # Display OSDBulder Home Path #================================================= if (!($HideDetails.IsPresent)) { Write-Host "Home $global:GetOSDBuilderHome" Write-Host "-Content $global:SetOSDBuilderPathContent" -ForegroundColor Gray Write-Host "-ContentPacks $global:SetOSDBuilderPathContentPacks" -ForegroundColor Gray Write-Host "-FeatureUpdates $global:SetOSDBuilderPathFeatureUpdates" -ForegroundColor Gray Write-Host "-OSImport $global:SetOSDBuilderPathOSImport" -ForegroundColor Gray Write-Host "-OSMedia $global:SetOSDBuilderPathOSMedia" -ForegroundColor Gray Write-Host "-OSBuilds $global:SetOSDBuilderPathOSBuilds" -ForegroundColor Gray Write-Host "-PEBuilds $global:SetOSDBuilderPathPEBuilds" -ForegroundColor Gray Write-Host "-Mount $global:SetOSDBuilderPathMount" -ForegroundColor Gray Write-Host "-Tasks $global:SetOSDBuilderPathTasks" -ForegroundColor Gray Write-Host "-Templates $global:SetOSDBuilderPathTemplates" -ForegroundColor Gray Write-Host "-Updates $global:SetOSDBuilderPathUpdates" -ForegroundColor Gray #Show-OSDBuilderHomeMap } #================================================= # Verify Single Version of OSDBuilder #================================================= if (($global:GetOSDBuilder.PSModuleOSDBuilder).Count -gt 1) { Write-Warning "Multiple OSDBuilder Modules are loaded" Write-Warning "Close all open PowerShell sessions before using OSDBuilder" Break } #================================================= # CreatePaths #================================================= if ($CreatePaths.IsPresent) { New-ItemDirectoryGetOSDBuilderHome New-ItemDirectorySetOSDBuilderPathContent New-OSDBuilderContentPack -Name '_Global' } #================================================= # Remove Directories #================================================= $OSDBuilderOldDirectories = @( "$SetOSDBuilderPathContent\UpdateStacks" "$SetOSDBuilderPathContent\UpdateWindows" "$SetOSDBuilderPathUpdates\Windows 10 1903" ) foreach ($item in $OSDBuilderOldDirectories) { if (Test-Path "$item") { Write-Warning "'$item' is no longer required and should be removed" } } #================================================= # DownloadOneDrive #================================================= if ($Quick -eq 'Download' -or $Download -eq 'OSMediaUpdates') { $HideDetails = $true Get-OSMedia | Update-OSMedia -Download Return } if ($Quick -eq 'Cleanup') { $HideDetails = $true Save-OSDBuilderDownload -Superseded Remove Return } if ($Download -eq 'FeatureUpdates') { $HideDetails = $true Save-OSDBuilderDownload -FeatureUpdates Return } if ($Download -eq 'OneDrive' -or $Quick -eq 'OneDrive') { $HideDetails = $true Save-OSDBuilderDownload -ContentDownload "OneDriveSetup Production" Return } if ($Download -eq 'OneDriveEnterprise') { $HideDetails = $true Save-OSDBuilderDownload -ContentDownload "OneDriveSetup Enterprise" Return } #================================================= # Show-OSDBuilderHome #================================================= if ($HideDetails -eq $false) { #================================================= # Display Home Content #================================================= if (!($HideDetails.IsPresent)) { if ($global:GetOSDBuilder.VersionOSDBuilder -gt $global:GetOSDBuilder.VersionOSDBuilderPublic) { Write-Host Write-Host "OSDBuilder Release Preview" -ForegroundColor Green Write-Host "The current Public version is $($global:GetOSDBuilder.VersionOSDBuilderPublic)" -ForegroundColor DarkGray } elseif ($global:GetOSDBuilder.VersionOSDBuilder -eq $global:GetOSDBuilder.VersionOSDBuilderPublic) { #Write-Host "OSDBuilder is up to date" -ForegroundColor Green #"" } else { Write-Host Write-Warning "OSDBuilder can be updated to $($global:GetOSDBuilder.VersionOSDBuilderPublic)" Write-Host "OSDBuilder -Update" -ForegroundColor Cyan } if ($global:GetOSDBuilder.VersionOSD -gt $global:GetOSDBuilder.VersionOSDPublic) { Write-Host Write-Host "OSD Release Preview" -ForegroundColor Green Write-Host "The current Public version is $($global:GetOSDBuilder.VersionOSDPublic)" -ForegroundColor DarkGray } elseif ($global:GetOSDBuilder.VersionOSD -eq $global:GetOSDBuilder.VersionOSDPublic) { #Write-Host "OSD is up to date" -ForegroundColor Green } else { Write-Host Write-Warning "OSD can be updated to $($global:GetOSDBuilder.VersionOSDPublic)" Write-Host "Update-Module OSD -Force" -ForegroundColor Cyan } Write-Host "" Write-Host "Latest Updates:" -ForegroundColor Gray foreach ($line in $global:GetOSDBuilder.PublicJson.OSDBuilderUpdates) {Write-Host $line -ForegroundColor DarkGray} Write-Host "" Write-Host "Helpful Links:" -ForegroundColor Gray foreach ($line in $global:GetOSDBuilder.PublicJson.OSDBuilderHelp) {Write-Host $line -ForegroundColor DarkGray} Write-Host "" Write-Host "New Links:" -ForegroundColor Gray foreach ($line in $global:GetOSDBuilder.PublicJson.OSDBuilderNew) {Write-Host $line -ForegroundColor DarkGray} } Show-OSDBuilderHomeTips } if ($UpdateModule.IsPresent) { Update-ModuleOSDBuilder } } |