Inplace-upgrade with USB?!

Hey, We have some of small customers at my job, it causes som problems that they dont have SCCM, or other deployment tools. So they have decided to handle out usb sticks with .ISO file. And in my world, Its almost forbidden but well, lets do the best of it.

Ok. So what I know, we need to pay attention to some stuff.

* Power supply
* Diskspace
* If the user pull the USB out
* Some popup´s so it’s easy for the user to go through this.
* If the user is already on the latest version. then we don’t need run this.
* Make it run totally offline. (so it does not need of any network connection)

Just follow the steps, and download the script here.
USB-stick – pontuswendt.blog

1. First thing, We do a .bat file that triggers the script, just because they can’t right click on the PowerShell script and run it as admin.

@setlocal enableextensions
@cd /d "%~dp0"
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& './Install-script-utan-preq.ps1'"

Save this in a folder.
2017-09-11 08_27_35-USB-stick.png

2. Now we need the iso, in my case Its ‘Windows 10 Pro Swe’, put it in the same folder as the script.
2017-09-11 08_30_44-USB-stick.png

3. Open Powershell ise, and start your script.
Always start a powershell script like this, because you should. Always


Always start a PowerShell script like this, because you should. Always

4 – Let’s begin with Prerequisite

4.1 Check if the 1703 version already exists

Write-Host "#Check if you allready have Windows 10 1703" -ForegroundColor magenta
if ((Get-CimInstance -ClassName Win32_OperatingSystem -Namespace root/cimv2).BuildNumber -ne "15063") {
   #Script continues
} Else {
     $wshell = New-Object -ComObject Wscript.Shell
     $wshell.Popup("You allready have Windows 10 1703 installed",0,"Done",0x0)
         If ("OK" -eq "OK") {
  Exit
  }  Else {
  Exit}
}

4.1 Check If you have a power supply connected. there´s a bunch of code down here now, that’s why I need to see if the computer is a Laptop or not, otherwise the results get very strange with desktops or hyper-v machines.

#Do function Get-Laptop
Function Get-Laptop
{
 Param(
 [string]$computer = "localhost"
 )
 $isLaptop = $false
 if(Get-WmiObject -Class win32_systemenclosure -ComputerName $computer |
    Where-Object { $_.chassistypes -eq 9 -or $_.chassistypes -eq 10 `
    -or $_.chassistypes -eq 14})
   { $isLaptop = $true }
 if(Get-WmiObject -Class win32_battery -ComputerName $computer)
   { $isLaptop = $true }
 $isLaptop
}
Write-Host "#Check if a Powersupply is connected. - CHECK" -ForegroundColor magenta
If(get-Laptop) {
 if ((Get-CimInstance win32_battery).batterystatus -eq "2") {
   #Script continues
} Else {
     [System.Windows.MessageBox]::Show('Hey, you need to connect the powersupply to continue, plug it in and try again.')
         If ("OK" -eq "OK") {
  Exit
  }  Else {
  Exit}
}
}

4.2 Check if the computer has more than 5 Gigabyte left on the disk(C:)

Write-Host "#Check if the computer have more than 5GIG on C: - CHECK" -ForegroundColor magenta
if ((Get-CimInstance Win32_Logicaldisk).Freespace -gt "5000000000") {
#Script continues
} Else {
     [System.Windows.MessageBox]::Show('Hey, you dont have diskspace for this upgrade, please try to remove files on your C: or contact the servicedesk.')
         If ("OK" -eq "OK") {
  Exit
  }  Else {
  Exit}
}
 

5. Let’s start the installation

5.1 Remove the C:\Win10 folder, (In case its corrupted files in the folder)

Write-Host "#Remove the C:\Win10 folder" -ForegroundColor magenta
Remove-Item  -Path "C:\Win10" -Force -Recurse -ErrorAction Continue | Out-Null

5.2 Create folder C:\Win10

Write-Host "#Create the C:\Win10 folder" -ForegroundColor magenta
New-Item -ItemType Directory -Path "C:\Win10" -Force | Out-Null
Remove-Item  -Path "C:\Win10" -Force -Recurse -ErrorAction Continue | Out-Null

5.3 Install the 7-zip on the machine ( We want to extract the .iso to C:\Win10)

Write-Host "#Installing 7-zip" -ForegroundColor magenta
.\7z1604-x64.exe /S -ErrorAction Continue | Start-sleep -s 10

5.4 Extract the .ISO to C:\Win10

Get-ChildItem .\SW_DVD5_Win_Pro_10_1703_64BIT_Swedish_MLF_X21-36776.iso | % {& "C:\Program Files\7-Zip\7z.exe" "x" $_.fullname "-oC:\Win10" -aoa}

5.5. Start the In-place-upgrade

Set-Location C:\Win10
.\setup.exe /Auto upgrade /DynamicUpdate Disable

6. Save the Install-script.ps1 to the same folder as the other files.
2017-09-11 09_24_43-USB-stick.png

7. Ok start the installation, by Right click on the Start-Inplace-upgrade.cmd and run as Admin
2017-09-11 09_27_33-sql.invidjkp.local - ASG-RemoteDesktop 2017 - 172.20.40.3.png

8. Installation is starting.
2017-09-11 09_41_11-Namnlös - Paint.png

2017-09-11 09_29_02-SERVICEDESK - Windows 10 uppgradering - Rutinbeskrivning.docx - Word.png

2017-09-11 09_29_21-SERVICEDESK - Windows 10 uppgradering - Rutinbeskrivning.docx - Word.png

9. We are done.

Thanks for reading
/pontus

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s