diff --git a/Public/New-OSBuild.ps1 b/Public/New-OSBuild.ps1 index 5951e05..8558b5f 100644 --- a/Public/New-OSBuild.ps1 +++ b/Public/New-OSBuild.ps1 @@ -1031,42 +1031,44 @@ function New-OSBuild { #=================================================================================================== if ($OSMajorVersion -eq 10 -and $OSInstallationType -eq 'Client') { Show-ActionTime - Write-Host -ForegroundColor Green "OS: Update OneDriveSetup.exe" - $OneDriveSetupDownload = $false - $OneDriveSetup = Join-Path $GetOSDBuilderPathContentOneDrive 'OneDriveSetup.exe' - if (!(Test-Path $OneDriveSetup)) {$OneDriveSetupDownload = $true} - - if (Test-Path $OneDriveSetup) { - if (!(([System.Io.fileinfo]$OneDriveSetup).LastWriteTime.Date -ge [datetime]::Today )) { - $OneDriveSetupDownload = $true - } - } -<# if ($OneDriveSetupDownload -eq $true) { - $WebClient = New-Object System.Net.WebClient - Write-Host "Downloading to $OneDriveSetup" -ForegroundColor Gray - $WebClient.DownloadFile('https://go.microsoft.com/fwlink/p/?LinkId=248256',"$OneDriveSetup") - } #> + $OneDriveFileName = 'OneDriveSetup.exe' + Write-Host -ForegroundColor Green -Object "OS: Update $OneDriveFileName" + $indent = ' ' # 18 spaces + # SET THE SYSTEM DIRECTORY BASED ON THE ARCHITECTURE OF THE OS if ($OSArchitecture -eq 'x86') { - $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\System32\OneDriveSetup.exe" | Select-Object -Property * - Write-Host -ForegroundColor Gray " Existing Image Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" - if (Test-Path $OneDriveSetup) { - robocopy "$GetOSDBuilderPathContentOneDrive" "$MountDirectory\Windows\System32" OneDriveSetup.exe /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-OneDriveSetup.log" | Out-Null - $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\System32\OneDriveSetup.exe" | Select-Object -Property * - Write-Host -ForegroundColor Gray " Updating with Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" - } + $SystemDirectory = "$MountDirectory\Windows\System32" } else { - $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\SysWOW64\OneDriveSetup.exe" | Select-Object -Property * - Write-Host -ForegroundColor Gray " Existing Image Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" - if (Test-Path $OneDriveSetup) { - robocopy "$GetOSDBuilderPathContentOneDrive" "$MountDirectory\Windows\SysWOW64" OneDriveSetup.exe /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-OneDriveSetup.log" | Out-Null - $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\SysWOW64\OneDriveSetup.exe" | Select-Object -Property * - Write-Host -ForegroundColor Gray " Updating with Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" + $SystemDirectory = "$MountDirectory\Windows\SysWOW64" + } + + # CREATE THE DIRECTORY PATHS FOR THE IMAGE AND OSDBUILDER CONTENT + $OneDriveSetupImagePath = Join-Path -Path $SystemDirectory -ChildPath $OneDriveFileName + $OneDriveSetupContentPath = Join-Path -Path $GetOSDBuilderPathContentOneDrive -ChildPath $OneDriveFileName + + # GET THE VERSION OF ONEDRIVE FROM THE IMAGE + $OneDriveSetupImageVersion = (Get-ItemProperty -Path $OneDriveSetupImagePath).VersionInfo.ProductVersion + Write-Host -ForegroundColor Gray -Object ($indent + "Image $OneDriveFileName Version: $OneDriveSetupImageVersion") + + # CHECK IF ONEDRIVE IS IN THE CONTENT DIRECTORY + if (Test-Path -Path $OneDriveSetupContentPath) { + # GET THE VERSION OF ONEDRIVE IN THE CONTENT DIRECTORY + $OneDriveSetupVersion = (Get-ItemProperty -Path $OneDriveSetupContentPath).VersionInfo.ProductVersion + Write-Host -ForegroundColor Gray -Object ($indent + "Content $OneDriveFileName Version: $OneDriveSetupVersion") + + # COPY ONEDRIVE FROM THE CONTENT DIRECTORY TO THE IMAGE DIRECTORY ONLY IF THE IMAGE HAS AN OLDER VERSION + if ([Version]$OneDriveSetupImageVersion -lt [Version]$OneDriveSetupVersion) { + Write-Host -ForegroundColor Gray -Object ($indent + "Updating the image with $OneDriveFileName version $OneDriveSetupVersion") + $null = robocopy "$GetOSDBuilderPathContentOneDrive" "$SystemDirectory" $OneDriveFileName /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-OneDriveSetup.log" + } else { + Write-Host -ForegroundColor Gray -Object ($indent + "The version of $OneDriveFileName in the content directory is not newer than the image") + Write-Host -ForegroundColor Gray -Object ($indent + "No changes to $OneDriveFileName will be made to the image") } } - Write-Host -ForegroundColor Cyan " To update OneDriveSetup.exe use one of the following commands:" - Write-Host -ForegroundColor Cyan " Save-OSDBuilderDownload -ContentDownload 'OneDriveSetup Enterprise'" - Write-Host -ForegroundColor Cyan " Save-OSDBuilderDownload -ContentDownload 'OneDriveSetup Production'" + + Write-Host -ForegroundColor Cyan -Object ($indent + 'To update the OneDrive content directory, use one of the following commands:') + Write-Host -ForegroundColor Cyan -Object ($indent + "Save-OSDBuilderDownload -ContentDownload 'OneDriveSetup Enterprise'") + Write-Host -ForegroundColor Cyan -Object ($indent + "Save-OSDBuilderDownload -ContentDownload 'OneDriveSetup Production'") } #=================================================================================================== # DismCleanupImage diff --git a/Public/Save-OSDBuilderDownload.ps1 b/Public/Save-OSDBuilderDownload.ps1 index 26c92eb..f9f7c23 100644 --- a/Public/Save-OSDBuilderDownload.ps1 +++ b/Public/Save-OSDBuilderDownload.ps1 @@ -224,34 +224,95 @@ function Save-OSDBuilderDownload { if ($PSCmdlet.ParameterSetName -eq 'Content') { - #=================================================================================================== - # Database - #=================================================================================================== - if ($ContentDownload -eq 'OneDriveSetup Production') { - $DownloadUrl = 'https://go.microsoft.com/fwlink/p/?LinkId=248256' - $DownloadPath = $GetOSDBuilderPathContentOneDrive - $DownloadFile = 'OneDriveSetup.exe' - } - if ($ContentDownload -eq 'OneDriveSetup Enterprise') { - $DownloadUrl = 'https://go.microsoft.com/fwlink/p/?linkid=860987' - $DownloadPath = $GetOSDBuilderPathContentOneDrive - $DownloadFile = 'OneDriveSetup.exe' + function Save-OneDriveSetup { + [CmdletBinding()] + param ( + # THE NAME OF THE FILE (ONEDRIVESETUP.EXE) + [Parameter(Mandatory = $true)] + [String] + $Name, + + # THE PATH WHERE THE FILE IS SAVED (C:\OSDBuilder\Content\OneDrive) + [Parameter(Mandatory = $true)] + [System.IO.FileInfo] + $Path + ) + + $filePath = "$Path\$Name" + + $iwrParams = @{ + OutFile = "$filePath" + Uri = '' + } + + # SET THE DOWNLOAD URL BASED ON ONEDRIVE SETUP TYPE + switch ($ContentDownload) { + 'OneDriveSetup Production' { + # LINK FOR THE PRODUCTION RING, LATEST RELEASE BUILD + $iwrParams.Uri = 'https://go.microsoft.com/fwlink/?linkid=844652' + } + + 'OneDriveSetup Enterprise' { + # LINK FOR THE DEFERRED RING, LATEST RELEASE BUILD + $iwrParams.Uri = 'https://go.microsoft.com/fwlink/?linkid=860987' + } + + Default {} + } + + # CHECK THE RELEASE NOTES PAGE FOR ONEDRIVE AND PARSE OUT THE LATEST VERSION NUMBER + $releaseNotes = 'https://go.microsoft.com/fwlink/?linkid=2159953' + $latestVersion = Invoke-WebRequest -Uri $releaseNotes -UseBasicParsing | + Select-Object -ExpandProperty Links | + Where-Object -Property 'href' -like -Value $iwrParams.uri | + Select-Object -Last 1 -ExpandProperty 'outerHTML' + $latestVersion = $latestVersion.Split('<>')[2] + + # CHECK IF THE ONEDRIVESETUP.EXE FILE ALREADY EXISTS + if ((Test-Path -Path "$filePath") -eq $false) { + Write-Verbose -Message "$Name not found at $Path" -Verbose + $exeExists = $false + } else { + $exeExists = $true + $exeOutdated = $false + + # GET THE VERSION NUMBER OF ONEDRIVESETUP.EXE + $exeVersion = (Get-ItemProperty -Path "$filePath").VersionInfo.ProductVersion + + # COMPARE THE VERSION OF ONEDRIVESETUP.EXE WITH WHAT'S LISTED ONLINE + if ([Version]$exeVersion -lt [Version]$latestVersion) { + Write-Verbose -Message "$Name $exeVersion is out of date. The latest version is $latestVersion..." -Verbose + $exeOutdated = $true + } + } + + # DOWNLOAD ONEDRIVESETUP.EXE IF IT DOESN'T EXIST OR IS OUTDATED + if (($exeExists -eq $false) -or ($exeOutdated -eq $true)) { + Write-Verbose -Message "DownloadUrl: $($iwrParams.Uri)" -Verbose + Write-Verbose -Message "DownloadPath: $Path" -Verbose + Write-Verbose -Message "DownloadFile: $Name" -Verbose + + try { + Write-Verbose -Message "Downloading $Name $latestVersion" -Verbose + Invoke-WebRequest @iwrParams -ErrorAction Stop + } catch { + Write-Warning -Message 'Content could not be downloaded' + } + } else { + Write-Verbose -Message "$Name does not need to be updated. Skipping download" -Verbose + Write-Verbose -Message "OneDriveSetup.exe Version: $exeVersion" -Verbose + Write-Verbose -Message "Latest Version: $latestVersion" -Verbose + } } #=================================================================================================== # Download #=================================================================================================== + $DownloadPath = $GetOSDBuilderPathContentOneDrive + $DownloadFile = 'OneDriveSetup.exe' + if (!(Test-Path "$DownloadPath")) {New-Item -Path $DownloadPath -ItemType Directory -Force | Out-Null} - Write-Verbose "DownloadUrl: $DownloadUrl" -Verbose - Write-Verbose "DownloadPath: $DownloadPath" -Verbose - Write-Verbose "DownloadFile: $DownloadFile" -Verbose - Invoke-WebRequest -Uri $DownloadUrl -OutFile "$DownloadPath\$DownloadFile" - if (Test-Path "$DownloadPath\$DownloadFile") { - $OneDriveSetupInfo = Get-Item -Path "$DownloadPath\$DownloadFile" | Select-Object -Property * - Write-Verbose "DownloadVersion: $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" -Verbose - Write-Verbose 'Complete' -Verbose - } else { - Write-Warning 'Content could not be downloaded' - } + + Save-OneDriveSetup -Path $DownloadPath -Name $DownloadFile } if (($PSCmdlet.ParameterSetName -eq 'OSDUpdate') -or ($PSCmdlet.ParameterSetName -eq 'OSDUpdateSuperseded')) {