Update Powershell through command line
Solution 1:
Run this command :
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
And then run the MSI with your parameters.
After this you need to update the modules.
Reference:
https://www.thomasmaurer.ch/2019/03/how-to-install-and-update-powershell-6/
https://www.thomasmaurer.ch/2019/02/update-powershellget-and-packagemanagement/
Solution 2:
Open Powershell as admin and type the following command:
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
If you want to update to the latest preview, add the -Preview
argument at the end:
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Preview"
Solution 3:
Here's a little trick using Chocolatey
#Install Chocolatey
#region
echo "Setting up Chocolatey software package manager"
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
Get-PackageProvider -Name chocolatey -Force
echo "Setting up Full Chocolatey Install"
Install-Package -Name Chocolatey -Force -ProviderName chocolatey
$chocopath = (Get-Package chocolatey |
?{$_.Name -eq "chocolatey"} |
Select @{N="Source";E={((($a=($_.Source -split "\\"))[0..($a.length - 2)]) -join "\"),"Tools\chocolateyInstall" -join "\"}} |
Select -ExpandProperty Source)
& $chocopath "upgrade all -y"
choco install chocolatey-core.extension --force
echo "Creating daily task to automatically upgrade Chocolatey packages"
# adapted from https://blogs.technet.microsoft.com/heyscriptingguy/2013/11/23/using-scheduled-tasks-and-scheduled-jobs-in-powershell/
$ScheduledJob = @{
Name = "Chocolatey Daily Upgrade"
ScriptBlock = {choco upgrade all -y}
Trigger = New-JobTrigger -Daily -at 2am
ScheduledJobOption = New-ScheduledJobOption -RunElevated -MultipleInstancePolicy StopExisting -RequireNetwork
}
Register-ScheduledJob @ScheduledJob
#endregion
#Update Powershell
#region
$ErrorActionPreference = "silentlycontinue"
$PSVersionTable.PSVersion
choco install powershell -y
choco upgrade powershell -y
$ErrorActionPreference = "continue"
#endregion
Solution 4:
You should download WMF 5.0 from here. Then run a command from cmd:
wusa.exe D:\W2K12-KB3134759-x64.msu
or where you've downloaded package.