The PowerShell team just announced PowerShell 7. PowerShell 7 is built on .NET Core 3 and brings back many APIs required by modules built on .NET Framework so that they work with .NET Core runtime. While PowerShell Core 6 was focusing on bringing cross-platform compatibility, PowerShell 7 will focus on making it a viable replacement for Windows PowerShell 5.1 and bringing near parity with Windows PowerShell. Here is how you can install and update PowerShell 7 on Windows and Linux using a simple one-liner.
If you want to know what’s new in PowerShell 7, check out my blog post!
One great example of how cross-platform PowerShell can work, check out my blog post: How to set up PowerShell SSH Remoting.
Install PowerShell 7
Before showing you the one-liner option to install PowerShell 7, I want to share with you the documentation to install PowerShell 7 on different operating systems like Windows, macOS, and Linux.
- Installing PowerShell Core on Windows
- Installing PowerShell Core on Linux
- Installing PowerShell Core on macOS
- Installing PowerShell Core on ARM
Install from the Microsoft Store
If you are running Windows 10, you can easily install PowerShell 7 and higher through the Microsoft Store.
You can search it in the Microsoft Store app on Windows 10 or you can simply use this link.
Install PowerShell 7 using winget
If you are running Windows 10, and you have a new command-line tool called winget. The winget command line tool enables you to easily discover, install, upgrade, remove and configure applications on Windows 10 computers.
You can simply type the following command, to get the latest version of PowerShell.
winget install PowerShell
Later you will also be able to automate the process to download apps from the Windows Store using Winget.
One-liner to install or update PowerShell 7 on Windows 10
Steve Lee (Microsoft Principal Software Engineer Manager in the PowerShell Team) shared some one-liner, which helps you quickly install and update:
You can use this single command in Windows PowerShell to install PowerShell 7.
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
There are additional switches to, for example, install daily builds of the latest PowerShell previews.
-Destination
The destination path to install PowerShell Core to.
-Daily
Install PowerShell Core from the daily build.
Note that the ‘PackageManagement’ module is required to install a daily package.
-Preview
Install the latest preview, which is currently version 7.
-UseMSI
Use the MSI installer.
-Quiet
The quiet command for the MSI installer.
-DoNotOverwrite
Do not overwrite the destination folder if it already exists.
-AddToPath
On Windows, add the absolute destination path to the ‘User’ scope environment variable ‘Path’;
On Linux, make the symlink ‘/usr/bin/pwsh’ points to “$Destination/pwsh”;
On MacOS, make the symlink ‘/usr/local/bin/pwsh’ points to “$Destination/pwsh”.
One-liner to install or update PowerShell 7 on Linux
You can use this as a single command to install PowerShell 7 on Linux.
wget https://aka.ms/install-powershell.sh; sudo bash install-powershell.sh; rm install-powershell.sh
Depending on your distro you are using, this will register Microsoft’s pkg repos and install that package (deb or rpm).
You can also use the following switches:
-includeide
Installs VSCode and VSCode PowerShell extension (only relevant to machines with a desktop environment)
-interactivetesting
Do a quick launch test of VSCode (only applicable when used with -includeide)
-skip-sudo-check
Use sudo without verifying its availability (hard to accurately do on some distros)
-preview
Installs the latest preview release of PowerShell side-by-side with any existing production releases
To currently run the PowerShell Preview, you can run the following command:
pwsh
After Installing
After you have installed PowerShell 7, also make sure to update PowerShellGet and the PackageManagement module.
You might ask, what my preferred way is? On Windows 10 I am definitely using the Microsoft Store and with winget I can easily do that from the command line. I hope this blog post was helpful. If you have any questions, please let me know in the comments.
Tags: download, install, Install PowerShell 7, Linux, macOS, Microsoft, One-liner, PowerShell, PowerShell 7, PowerShell 7 Preview, preview, pwsh, update, Update PowerShell, Update PowerShell 7, Windows, Windows 10, Windows Server Last modified: July 16, 2021
You can also use my PSReleaseTools module (https://github.com/jdhitsolutions/PSReleaseTools) which is in the PowerShell Gallery. It works cross platform and you can easily download setup files. Here’s how you could download and install the 64bit msi for Windows 10:
Get-PSReleaseAsset -Preview -Family Windows -Only64Bit | where format -eq ‘msi’ | Save-PSReleaseAsset -Path d:\ -Passthru | Invoke-Item
Hi Thomas,
How do I update or install PowerShelll 7 in disconnected environment ? These are machines with no outside connectivity.
Thanks,
Hi, In that case, you just download the MSI installer from GitHub and copy it to the machine :)
https://github.com/powershell/powershell You have a download table, make sure you for PowerShell 7, that you download the preview version.
Was so happy I can finally install the MSOnline module but Powershell 7 can’t get seem to get passed a “Could not load type ‘System.Security.Cryptography.SHA256Cng” error when I try to Connect-MSOnlineService . Hopefully they can get passed it by the time it becomes GA.
If you are on a Linux system that supports snaps you can install both the current and preview versions of Powershell from the Snap store.
e.g. for Powershell 6 – sudo snap install powershell –classic
and for Powershell 7 – sudo snap install powershell-preview –classic
Note that these snaps are published by Microsoft. Also the –classic flag is required as the snaps are published with classic confinement.
Is powershell 7 currently available for MAC Sierra edition? Thank you
Thanks Thomas
Is it possible to add powershell 7 to winPE?
Can PowerShell 7 be used to “upgrade” Powershell 5.1 on Server 2016 or are they dual-installed given 5.1 is Windows centric while v7 is mutli-source OS based?
Hi Steve! Windows PowerShell 5.1 and PowerShell 7 are side-by-side installations. (Like PowerShell Core 6 and Windows PowerShell 5.1)
I must do something wront ;'(
PS C:\Windows\system32> iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
Invoke-Expression : A positional parameter cannot be found that accepts argument ‘iex’.
At line:1 char:1
+ iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”i …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
super late and you may have solved it already, but i just had to say something; you entered it twice — you entered:
iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
you need to enter:
iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
Unexpected token ‘-UseMSI’ in expression or statement.
At line:1 char:1
+ iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
Ah, I was pasting the url encoded ampersand (& amp ;) from the blog here. Replace with just the ampersand (&) and bingo!
Sorry for that, my CMS sometimes tries to fix my code ;)
Thanks easy install!
For MDT or SCCM you could also use:
msiexec.exe /package PowerShell-7.0.0-win-x64.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1
How does one replace PS 5.1 right click context ‘run with PowerShell’ so that it points to 7?
Thanks for this. I wonder if there is an easy way to make PowerShell 7 the default from the Windows right click menu? TIA.
I’d like to install PS 7 and Visual Studio Code with AWS Tools on Win 10. What’s the best way to set this combo up?
It is just crashing after the launch
PS C:\Program Files (x86)\PowerShell\7> .\pwsh.exe
Unhandled exception. System.TypeInitializationException: The type initializer for ‘System.Management.Automation.Tracing.
PSEtwLog’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘System.Management.Automation.Tracing.PSEtwLogProvide
r’ threw an exception.
—> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Globalization.CultureData.GetNFIValues(NumberFormatInfo nfi)
at System.Globalization.NumberFormatInfo..ctor(CultureData cultureData)
at System.Globalization.CultureInfo.get_NumberFormat()
at System.Globalization.CultureInfo.GetFormat(Type formatType)
at System.Globalization.NumberFormatInfo.get_CurrentInfo()
at System.Guid.TryParseExactD(ReadOnlySpan`1 guidString, GuidResult& result)
at System.Guid.TryParseGuid(ReadOnlySpan`1 guidString, GuidResult& result)
at System.Guid..ctor(String g)
at System.Management.Automation.Tracing.PSEtwLogProvider..cctor()
— End of inner exception stack trace —
at System.Management.Automation.Tracing.PSEtwLog..cctor()
— End of inner exception stack trace —
at System.Management.Automation.Tracing.PSEtwLog.LogConsoleStartup()
at Microsoft.PowerShell.UnmanagedPSEntry.Start(String consoleFilePath, String[] args, Int32 argc)
at Microsoft.PowerShell.ManagedPSEntry.Main(String[] args)
PS C:\Program Files (x86)\PowerShell\7>
I love this command and use it all the time!
I discovered the issue with your command and the pic of the powershell window above shows what went wrong.
Your command below the pic is this: (wrong) iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI” (wrong)
The part that is missing is the -Preview at the end of the command. The working command is:
(working) iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Preview” (working)
Thank you for the post! As an IT professional, I find Powershell to be a major time and life saver and is a requirement to learn for any serious Windows Support Professional.
Thank you Jeremy
For the command without -Preview works fine. If you add -Preview it will install the latest preview which right now I think is 7.1.
However, I will check :)
Hey Thomas, the code to copy still contains amp; after the & symbol.
Thanks, Marc
Something changes it when the blog gets updated. I fixed it again.
Thank you so much.
If we want to update the PowerShell Module , I guess we don’t simply run UpdateModule as we can do with PowerShell Windows
So do we run:
iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
Hi Daniel. You still run Update-Modules to update the PowerShell modules. The command is to update the PowerShell version itself.
regards Thomas
Hi Thomas,
The one-liner command is great and it works for me.
Do you have a similar command that would return for latest available version number? So that I can compare with what I have installed already on my machine i.e. I don’t want to initiate the one liner if I’ve already got the latest.
e.g. …
Invoke-Expression “& { $(Invoke-RestMethod https://aka.ms/latest-version-powershell.ps1) }”
7.3
Thanks,
John
If I understood correctly,
$PSVersionTable.PSVersion
should do the trickHi Thomas,
Sorry I was not clear …
I was looking for a programmatic way to determine the most recent stable version of PowerShell Core on GitHub and compare it to my local version.
I worked it out and put a function together …
function OnLatestPowerShellCoreStableRelease {
$req = $null
try {
$req = [System.Net.WebRequest]::Create(‘https://github.com/PowerShell/PowerShell/releases/latest’);
$resp = $req.GetResponse()
if ([System.Net.HttpStatusCode]::OK -ne $resp.StatusCode) {
throw
}
}
catch {
return $null
}
$resp.ResponseUri.AbsoluteUri -match ‘\/v([0-9]+\.[0-9]+\.[0-9]+)$’
$versionString = $matches[1]
if (([System.Version] $PSVersionTable.PSVersion) -lt ([System.Version] $versionString)){
return $false
}
return $true
}
… it uses the “https://github.com/PowerShell/PowerShell/releases/latest” redirect/label to get the latest available version number.
Any idea how to solve this?
Unpacking powershell (7.0.2-1.ubuntu.18.04) …
dpkg: error processing archive /var/cache/apt/archives/powershell_7.0.2-1.ubuntu.18.04_amd64.deb (–unpack):
trying to overwrite ‘/usr/bin/pwsh’, which is also in package powershell-lts 7.0.0-1.ubuntu.18.04
Errors were encountered while processing:
/var/cache/apt/archives/powershell_7.0.2-1.ubuntu.18.04_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
Congratulations! PowerShell is installed at /opt/microsoft/powershell/7-lts.
Run “pwsh” to start a PowerShell session.
*** NOTE: Run your regular package manager update cycle to update PowerShell
I have 7.0 installed (not my machine), but I do want to upgrade.
Would love to do this (Windows 10, PS 5.1), but the machine I’m using won’t run the command properly:
PS C:\WINDOWS\system32> iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
irm : Unable to connect to the remote server
At line:1 char:12
+ iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I’ve done some googling on the error but haven’t found a page which actually helps. Hoping this one will. Thanks.
Looks like the machine you are running this script on doesn’t have internet access? Is that possible?
Successfully installed PowerShell 7.0.2.
Now attempting to configure Windows Terminal to open a powershell 7.0.2 tab. In the settings.json file, it seems I need the GUID for this software. Where do I find it?
It should be automatically added to the settings. Just close and reopen the Windows Terminal.
Hi Thomas, I guess something must have changed because when I use the one-liner with -UseMSI parameter, the installer gets stuck prompting to close the very PWSH session that I am running this one-liner from. Am I doing something wrong here?
There are two options, either try to close the PWSH Window or reboot later? I was hoping by using the one liner, I can just silently update the PS7. Please let me know where I am going wrong.
iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
I had the same issue. But on restarting pwsh it was at 7.1.0. So perhaps it’s past the point of installing? I also just tried:
start-job (iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”)
and was able to close the pwsh window and leave the installer running.
Thanks to Jeff Hicks for his solution, but I don’t understand MS why they create products with ugly basic things like upgrade. I expected “pwsh upgrade” command out of the box, rather then googling some side solutions
How do I make Powershell 7 the default when opening Powershell? Right now it defaults to Powershell 5.1.
I am running Windows Server 2012 and 2016.
Well, PowerShell 7 and Windows PowerShell 5.1 run side by side. PowerShell 7 is pwsh.exe and Windows PowerShell 5.1 is powershell.exe. So these are different entry points/shortcuts.
Does that make sense?
Hi Thomas
Nice guide you have made here. I just love using PowerShell and figure out new way to do things making small scripts.
thanks, I agree!
Hi Thomas,
I have the latest preview of windows 10 and when try to update to latest PowerShell preview I get this error:
iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Preview”
Invoke-RestMethod:
Line |
346 | … $metadata = Invoke-RestMethod https://raw.githubusercontent.com/Power …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception of type ‘System.Net.InternalException’ was thrown. -2146892963
Any idea? Best Regards
there is a formatting error in the iex command. looks like it took your ampersand and added “amp”
thanks! should be fixed now!
I’m confused, I run this (on fresh VM of Windows Server 2022):
iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI
>>>> “VERBOSE: About to download package from’https://github.com/PowerShell/PowerShell/releases/download/v7.2.0/PowerShell-7
.2.0-win-x64.msi’
But I don’t see powershell 7, just 5.1:
PS C:\Windows\system32> $PSVersionTable.PSVersion
Major Minor Build Revision
—– —– —– ——–
5 1 20348 320
I tried running pwsh but that’s not recognized.
Windows PowerShell 5.1 and PowerShell 7 run site by site. Windows PowerShell runs as powershell.exe and if you want to run PowerShell 7 there is pwsh.exe to run.
Still useful after all these years, Thank you for posting this.
Hey Thomas, from the current powershell terminal:
“winget install Microsoft.Powershell”
This will install from the current winget source if the above winget command fails.
Cheers!