r/PowerShell • • Mar 04 '20

Announcing PowerShell 7.0 | PowerShell

https://devblogs.microsoft.com/powershell/announcing-powershell-7-0/?WT.mc_id=reddit-social-marouill
281 Upvotes

74 comments sorted by

21

u/idontknowwhattouse33 Mar 04 '20
(Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json).ReleaseTag -replace '^v' -eq '7.0.0' ? 'Happy PowerSheller' : 'A sad day'

14

u/Yevrag35 Mar 04 '20

And download it like a boss:

$latest = Invoke-RestMethod 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest'

$downloadUrl = $latest.assets | Where-Object Name -like "*win-x64.msi" | Select-Object -ExpandProperty 'browser_download_url'
$fileName = Split-Path $downloadUrl -Leaf

$webClient = New-Object System.Net.WebClient
try {
    $webClient.DownloadFile($downloadUrl, "$PSScriptRoot\$fileName")
}
finally {
    $webClient.Dispose()
}

6

u/spyingwind Mar 04 '20
[Version]$ReleaseVersion = (Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json).ReleaseTag -replace '^v'
if ($PSVersionTable.PSEdition -like "Core" -and $ReleaseVersion -gt $PSVersionTable.PSVersion){
    $latest = Invoke-RestMethod -Uri "https://api.github.com/repos/PowerShell/PowerShell/releases" | Where-Object {$_.tag_name -eq "v$ReleaseVersion"}
    $downloadUrl = $latest.assets | Where-Object Name -like "*win-x64.msi" | Select-Object -ExpandProperty 'browser_download_url'
    Invoke-WebRequest -Uri $downloadUrl -OutFile "$PSScriptRoot\$(Split-Path $downloadUrl -Leaf)"
}

This should check if the current version of Core is the latest release, and download it if it isn't.

5

u/chadbaldwin Mar 05 '20

Why not just use the installer that they provide?

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -AddExplorerContextMenu -EnablePSRemoting -Quiet";

You can also use -Preview and -Daily to get different release versions.

1

u/spyingwind Mar 05 '20

Becaule iex is blocked by many AV's.

1

u/chadbaldwin Mar 05 '20

ahhh, that's interesting. I didn't know that.

I guess the work around could be...

irm https://aka.ms/install-powershell.ps1 | Out-File install-powershell.ps1
.\install-powershell.ps1 -UseMSI -AddExplorerContextMenu -EnablePSRemoting

?

1

u/spyingwind Mar 05 '20

That may work, but it effectively does the same thing, but downloads a script, which is what likely triggers AV. My bit of code doesn't download a script, but the MSI that can be authenticated with it's built in cert.

1

u/Sansred Jun 15 '20

This should be part of PowerShell, named something like Update-PowerShell

1

u/chadbaldwin Jun 15 '20

You'd think so. Usually with things like this...there's always some simple answer why they are unable to implement it. lol.

I guess until then, you can make it an alias. haha.

5

u/halbaradkenafin Mar 05 '20

Choco install pwsh or choco upgrade pwsh is even easier

15

u/[deleted] Mar 04 '20

Is anyone currently installing Powershell 6 or 7 in a production enterprise environment?

6

u/spyingwind Mar 04 '20

We plan on using it as a self contained tool that doesn't require much other than disk space.

5

u/Vexxt Mar 05 '20

workstation yes, server no.

5

u/Guyver1- Mar 05 '20

Im using it in production for reporting I publish to an internal reporting web site i built.

Reports like installed software on all domain servers, all machine certificates, roles and features, scheduled tasks etc etc.

The Parallelization of ForEach-Object has brought some of these scripts down from a 55 minute runtime down to just 2 minutes.

4

u/SteveL_Msft Software Engineering Manager, PowerShell Mar 05 '20

Installed 7 on all my development machines

3

u/bukem Mar 05 '20

We are using daily builds since PowerShell appeared on GitHub.

3

u/halbaradkenafin Mar 05 '20

Yes, both on my main devices and via AWS Lambda and Azure Functions

2

u/gordonv Mar 04 '20

Nah, home PC

0

u/[deleted] Mar 05 '20

[deleted]

3

u/Hoggs Mar 05 '20

I'm using it on the ubuntu agent for azure devops pipelines!

Why? Because I know it, and I can easily process json files used in my pipeline... try doing that with bash. ;)

2

u/cyp3d Mar 05 '20

what is wrong with jq?

cat file.json | jq .Item[].Metadata.labels

0

u/[deleted] Mar 05 '20

[deleted]

2

u/PMental Mar 05 '20

All the basic stuff still applies, and when you know that the new stuff will be easy to understand and use.

12

u/Pugway Mar 04 '20 edited Mar 04 '20

So for a Windows-only shop (primarily), is there any advantage to upgrading over PS 5.1? Won't happen until O365 support gets added anyway, I suppose.

EDIT: This is a good blog post that goes into more detail on the features in PS7 that may be of use: https://www.thomasmaurer.ch/2020/03/whats-new-in-powershell-7-check-it-out/

Still curious to see if there are any compatibility issues with older PS stuff. Sounds like they did a lot of work to bring 7 in line and finally surpassing 5.1

6

u/[deleted] Mar 04 '20

Pretty sure it has O365 support. I believe 6 did so 7 would with ease.

3

u/Pugway Mar 05 '20

I was going off this quote from the blog post

For those modules still incompatible, we’re working with a number of teams to add native PowerShell 7 support, including Microsoft Graph, Office 365, and more.

Which implies that it isn't supported. Maybe supported in 6 but not 7?

4

u/Vexxt Mar 05 '20

There are many different modules, some work, some dont.

AzureAD and Graph dont auth yet, but i think the teams module is fine for example.

6

u/blaughw Mar 05 '20

And thank god the modules are different. I don't need Sharepoint cmdlets in my Exchange session, or my Compliance Center session, or my MCO (Skype) session!

3

u/poshftw Mar 05 '20

PS7 is installed side-by-side, it does NOT replace PS5.
So you can safely install it, use PS5 as you did for all stuff what requires it, while moving forward with PS7 for any new stuff.

6

u/Sunsparc Mar 04 '20

Wish they would have kept the Preview icon, had a sort of outrun theme to it and looked cool.

5

u/SteveL_Msft Software Engineering Manager, PowerShell Mar 05 '20

You can download any of the icons from https://github.com/PowerShell/PowerShell/tree/master/assets and change it for your installation. PS7.1-preview.1 will have the preview icon :)

1

u/Kholtien Mar 05 '20

The preview icons are still in the assets folder. At least on mine anyway.

5

u/Emiroda Mar 05 '20

To remind everyone, the ActiveDirectory module works perfectly fine in PowerShell 7.0.

Here's my reddit post.

Here's Microsoft's official words, on the Announcing PowerShell 7.0 blog:

Which Microsoft products already support PowerShell 7?

Any module that is already supported by PowerShell Core 6.x is also supported in PowerShell 7, including:

On Windows, we’ve also added a -UseWindowsPowerShell switch to Import-Module
to ease the transition to PowerShell 7 for those using still incompatible modules. This switch creates a proxy module in PowerShell 7 that uses a local Windows PowerShell process to implicitly run any cmdlets contained in that module. For more information on this functionality, check out the Import-Module documentation.

For those modules still incompatible, we’re working with a number of teams to add native PowerShell 7 support, including Microsoft Graph, Office 365, and more.

3

u/sGillian Mar 04 '20

Is it possible with 7.0 to install PS modules on MacOS?

Hate to have to open Windows VM’s all the time to do some management.

7

u/ka-splam Mar 04 '20

Yes, although not any and all PS modules, only ones which support macOS and ps v7.

I.e. not the AD ones you probably want.

1

u/sGillian Mar 04 '20

Specifically looking for Azure AD, Exchange Online and security and compliance center

5

u/rjmholt Mar 04 '20

A common solution is to use pwsh on macOS to remote into Windows boxes to perform administration. Certainly I've seen a number of people running cloud and on-prem setups from their MacBooks.

4

u/nerddtvg Mar 04 '20

Azure AD and Exchange Online require .NET 4.5, so unfortunately not. Whenever the AzureAD.Standard.Preview module comes out, that will work.

2

u/me_again Mar 05 '20

AzureAD.Standard.Preview likely won't ship, the AzureAD folks are focusing on Microsoft.Graph module instead. https://developer.microsoft.com/en-us/office/blogs/microsoft-graph-powershell-preview-now-on-powershell-gallery/

1

u/nerddtvg Mar 05 '20

Oh great, yet another module. Since we still have to use MSOnline occasionally, unless they're going to actually finish making Graph a parity API to the old AzureAD endpoint, this still won't be enough.

-2

u/Sansred Mar 04 '20

Look at Powershell Core

9

u/ka-splam Mar 04 '20

The Core name is gone, it’s just powershell now, and 7 is the latest in that series.

2

u/Sansred Mar 04 '20

Thanks. Had a nagging suspicion in the back of my head that was the case.

3

u/Schmalhorst Mar 05 '20

Being powershell heavy at work, just knowing that a community driven upgrade is very appreciated and supported! Me <3 PoSh

3

u/diceytroop Mar 05 '20

Lots of nice things in here. Ternary statements and null conditional operators in particular leap out at me as huge, boilerplate-reducing features. Nice work.

3

u/jsiii2010 Mar 05 '20 edited Mar 05 '20

Ways to run things in parallel in powershell:

  1. jobs (processes) (or threadjobs in PS 6/7 or the module)

  2. start-process

  3. workflows (going away)

  4. powershell api with another runspace (more difficult to code)

  5. invoke-command with an array of multiple computers, which can all be localhost (have to be admin)

  6. multiple session (runspace) tabs in the ISE, or remote powershell ISE tabs (bye ISE)

  7. Powershell 7 has a foreach-object -parallel, as an alternative for #4

5

u/motsick Mar 04 '20

Dumb question: Can you install 7 along side 5 or will it replace the previous version.

10

u/Hexalon00 Mar 04 '20

Alongside

5

u/[deleted] Mar 04 '20

Yes you can

5

u/spyingwind Mar 04 '20

Yes, but the powershell exe is named pwsh to stop it from conflicting with 5.1 or less versions.

2

u/SMFX Mar 04 '20

Yeaaaaa!!!

2

u/boffhead Mar 04 '20

Now when's AWS adding it to Lambda :)

5

u/SteveL_Msft Software Engineering Manager, PowerShell Mar 05 '20

AWS Lambda already supported PowerShell Core 6 (https://aws.amazon.com/about-aws/whats-new/2018/09/aws-lambda-supports-powershell-core/). I expect they would move to PowerShell 7 pretty soon.

0

u/[deleted] Mar 04 '20

[deleted]

6

u/rjmholt Mar 04 '20

.NET Core 3.1 is LTS; it’s how PS 7 is LTS

2

u/Atomic0691 Mar 05 '20

Does PowerShell 7.0 have native AD support on windows machines?

7

u/SteveL_Msft Software Engineering Manager, PowerShell Mar 05 '20

Yes on latest versions of Windows 10 or Windows Server 2016/2019 as the AD Module needed to be updated. On older Windows systems, PowerShell 7 has a new feature to load incompatible modules in Windows PowerShell 5.1 implicitly. The only functional difference is that objects returned by those cmdlets are not live meaning you can't invoke methods on them (same as any remoting object). Also, the AD PSDrive won't work as that's not supported over implicit remoting.

1

u/Snak3d0c Mar 06 '20

Next up: group policy please 🙏

2

u/Emiroda Mar 05 '20

Yes. It's been there since PowerShell 6.1.1 on Windows 10 1809 and newer.

https://www.reddit.com/r/PowerShell/comments/f6qef2/psa_activedirectory_module_works_natively_with/

2

u/beerdini Mar 05 '20

Outside of whatever comes from doing Windows Updates, I haven't really looked at upgrading PowerShell before since before recently, I never really used it aside from for niche tasks. Is there any compatibility concerns if I upgrade from 5 to 7 on my system and connect to a domain controller and other systems that I don't have the ability to upgrade?

3

u/SteveL_Msft Software Engineering Manager, PowerShell Mar 05 '20

PowerShell 7 installs side-by-side with Windows PowerShell 5.1 so any existing scripts relying on powershell.exe will continue to work while you can develop new scripts to use pwsh.exe.

2

u/hbro Mar 05 '20

Is that fancy new secrets system included? Or is it a separate module?

1

u/signofzeta Mar 05 '20

I see the macOS and Linux releases have separate downloads, PowerShell and PowerShell-LTS. What’s the difference?

2

u/rjmholt Mar 05 '20 edited Mar 05 '20

The LTS packages get different updates. When 7.1 is released in a year or so, non-LTS will upgrade and LTS will not (instead just taking servicing updates).

On Linux that has to be a separate package because package managers need it to be. The servicing channel is baked into the package metadata.

I didn’t see a macOS LTS package, but given the pkg release asset doesn’t have its own update mechanism, I don’t think there is one.

There is indeed one! I’m guessing this is to help brew with release channels.

On Windows and macOS, you’ll get update notifications when new releases come out. You can change your preferences on what releases (as in which channel) you get notified for by defining $env:POWERSHELL_UPDATECHECK.

1

u/signofzeta Mar 05 '20

I accidentally downloaded the macOS one. I'll switch it to the "real" one. Thanks for clarifying!

1

u/serendrewpity Mar 05 '20

Not really sure what all the excitement is. I guess I assumed thta powershell could most definitely accomplish something like this already. I'd beed doing parallel processing with function callbacks and ExecQueryAsync in vbScript since its early days in WinXP.

I'm being serious, not picking a fight, I want to know why its a big deal that PS is just now getting around to this.

9

u/SteveL_Msft Software Engineering Manager, PowerShell Mar 05 '20

Regarding specifically parallelization, you could have always done this yourself with PowerShell runspaces. This is what modules like Posh-RS used. The new `ForEach-Object -Parallel` just makes it dead simple for users who don't understand or care about threading. PowerShell 7 has many other improvements over PowerShell Core 6 which itself has many improvements over Windows PowerShell 5.1 (see some of our blogs posts about that: https://aka.ms/psblog)

4

u/Emiroda Mar 05 '20

I'm pissing on /u/SteveL_Msft's parade, but Foreach-Object -Parrallel is not the big feature of PowerShell 7.0. As you said, you've been able to do parrallelisation for a long time. It's just that, on the box, Foreach-Object -Parrallel is the only thing people care about, specifically for PowerShell 7.0.

No, the big feature of PowerShell 7.0 is that it's the first version of PowerShell to be cross-platform, built on a new framework, and be viable for Windows users. As a Windows user, PowerShell 6 was forgettable. PowerShell 7.0 is the first stable version of PowerShell since 5.1 to be a viable option for development and production workloads, on Windows and Linux.

Besides, I think cross-platform DSC is more impressive.

3

u/serendrewpity Mar 05 '20

thank you. That is huge. Together with Windows Subsytem for Linux may just be a comprehensive, viable option to blur the llines Linux and Windows and increasing their footprint in the mobile, sbc, cloud and other platforms where linux had little competition from MS

0

u/[deleted] Mar 04 '20

[deleted]

13

u/jsiii2010 Mar 04 '20 edited Mar 04 '20

You can use start-threadjob too which has been around since ps 6, which doesn't serialize objects like jobs and psremote.

9

u/gordonv Mar 04 '20

Is this a simplified version of RunSpacePool/threads?

If so, this is definitely a cool upgrade.

3

u/MysticRyuujin Mar 05 '20

It's a simplified version of RunSpaces, but not pools. They blogged about it a little while ago. They said they might be able to optimize it more in the future but they were worried about leaking something using pools.

2

u/dedroia Mar 09 '20

I also worry about leaking when using pools.

0

u/[deleted] Mar 04 '20

[deleted]

10

u/SteveL_Msft Software Engineering Manager, PowerShell Mar 05 '20

PS7 is a superset of PSCore6 and brings back lots of compatibility with WinPS5.1. So from that perspective, it's an upgrade over PSCore6 while still side-by-side with WinPS5.1. If you really want side-by-side with 6, you can install 6 or7 from the zip package (install means unpack and run pwsh.exe).