Advertisement
nullzilla

Task - Upgrade Windows 10

Jan 10th, 2020 (edited)
1,916
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module $env:SyncroModule -WarningAction SilentlyContinue
  2.  
  3. # Scratchpad:
  4. # Removal
  5. # C:\Windows10Upgrade\Windows10UpgraderApp.exe /ForceUninstall
  6. # Del C:\Windows\UpdateAssistant\*.* /F /Q
  7.  
  8. #================================================================================
  9. # Configuration
  10. #================================================================================
  11.  
  12. # Application name (this will be used to check if application already installed)
  13. $name = "Windows 10"
  14.  
  15. # Download URL (redirects will be followed)
  16. $dlurl = 'https://go.microsoft.com/fwlink/?LinkID=799445'
  17.  
  18. # Installer filename (can be blank if download isn't a zip, wildcards allowed)
  19. $installer = "Windows10Upgrade*.exe"
  20.  
  21. # Arguments to use for installer (can be blank)
  22. $arg = "/QuietInstall /SkipEULA /SkipSelfUpdate /ShowOOBE none"
  23.  
  24. # Disk space required in MB (leave blank for no requirement)
  25. $diskspacerequired = '11000'
  26.  
  27. # Temporary storage location (no trailing \)
  28. $homepath = "c:\windows\temp"
  29.  
  30. #================================================================================
  31. # Shouldn't need to edit anything below this line
  32. #================================================================================
  33.  
  34. Write-Output "$name installation starting..."
  35.  
  36. Write-Output "Checking disk space..."
  37. $disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='$env:SystemDrive'" | Select-Object FreeSpace
  38. $disk = ([Math]::Round($Disk.Freespace / 1MB))
  39. if ($disk -lt $diskspacerequired) {
  40.     write-output "$name requires $diskspacerequired MB to install but there's only $disk MB free."
  41.     exit 1
  42. }
  43.  
  44. # Test for home directory and create if it doesn't exist
  45. if (-not (Test-Path $homepath)) { mkdir $homepath | Out-Null }
  46. Set-Location $homepath
  47.  
  48. # Prevent "You can’t install Windows on a USB flash drive using Setup" Error
  49. if (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control' -Name 'PortableOperatingSystem' -ErrorAction 'SilentlyContinue') {
  50.     Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control' -Name 'PortableOperatingSystem' -Value 0
  51. }
  52.  
  53. # Retrieve headers to make sure we have the final destination redirected file URL
  54. $dlurl = (Invoke-WebRequest -UseBasicParsing -Uri $dlurl -MaximumRedirection 0 -ErrorAction Ignore).headers.location
  55. Write-Output "Downloading: $dlurl"
  56. $dlfilename = [io.path]::GetFileName("$dlurl")
  57. (New-Object Net.WebClient).DownloadFile("$dlurl", "$homepath\$dlfilename")
  58.  
  59. # Use GCI to determine filename in case wildcards are used
  60. $installer = (Get-ChildItem $installer).Name
  61. Write-Output "Installing: $homepath\$installer $arg"
  62. Start-Process "$installer" -ArgumentList "$arg"
  63.  
  64. Write-Output "Cleaning up..."
  65. Start-Sleep -s 120
  66. Remove-Item $installer -Force
  67.  
Advertisement
RAW Paste Data Copied
Advertisement