2024-01-25 13:37:12 +01:00
Script: *upgrade-ubuntu.ps1*
========================
2021-11-08 21:36:42 +01:00
2022-02-10 09:01:07 +01:00
This PowerShell script upgrades Ubuntu Linux to the latest (LTS) release.
2021-11-08 21:36:42 +01:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2021-11-08 21:36:42 +01:00
```powershell
2023-07-29 10:15:44 +02:00
PS> ./upgrade-ubuntu.ps1 [< CommonParameters > ]
2021-11-08 21:36:42 +01:00
[< CommonParameters > ]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Example
-------
2021-11-08 21:36:42 +01:00
```powershell
PS> .\upgrade-ubuntu.ps1
```
2023-07-29 10:04:38 +02:00
Notes
-----
2022-11-17 19:46:02 +01:00
Author: Markus Fleschutz | License: CC0
2021-11-08 21:36:42 +01:00
2023-07-29 10:04:38 +02:00
Related Links
-------------
2021-11-08 21:36:42 +01:00
https://github.com/fleschutz/PowerShell
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
< #
.SYNOPSIS
Upgrades Ubuntu Linux
.DESCRIPTION
This PowerShell script upgrades Ubuntu Linux to the latest (LTS) release.
.EXAMPLE
PS> .\upgrade-ubuntu.ps1
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
""
2023-05-26 12:20:18 +02:00
"⏳ (1/4) Perform a backup!"
2022-11-17 20:02:26 +01:00
"It's strongly recommended to backup your data BEFORE the upgrade!"
2023-05-26 12:20:18 +02:00
$Confirm = Read-Host "Press < Return > to continue..."
2022-11-17 20:02:26 +01:00
""
2023-05-26 12:20:18 +02:00
"⏳ (2/4) Install update-manager-core, Upgrade Packages & Reboot"
$Confirm = Read-Host "Enter < yes > to perform this step (otherwise it will be skipped)"
2022-11-17 20:02:26 +01:00
if ($Confirm -eq "yes") {
sudo apt install update-manager-core
sudo apt update
sudo apt list --upgradable
sudo apt upgrade
sudo reboot
}
""
2023-05-26 12:20:18 +02:00
"⏳ (3/4) Remove obsolete kernel modules"
$Confirm = Read-Host "Enter < yes > to perform this step (otherwise it will be skipped)"
2022-11-17 20:02:26 +01:00
if ($Confirm -eq "yes") {
sudo apt --purge autoremove
}
""
2023-05-26 12:20:18 +02:00
"⏳ (4/4) Upgrade Ubuntu & reboot"
$Confirm = Read-Host "Enter < LTS > to upgrade to latest LTS release, < latest > to upgrade to latest Ubuntu release (otherwise this step will be skipped)"
2022-11-17 20:02:26 +01:00
if ($Confirm -eq "LTS") {
sudo do-release-upgrade
sudo reboot
} elseif ($Confirm -eq "latest") {
sudo do-release-upgrade -d
sudo reboot
}
"✔️ Done."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2024-05-19 10:25:56 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of upgrade-ubuntu.ps1 as of 05/19/2024 10:25:27)*