Last active
October 17, 2018 10:32
-
-
Save SteveL-MSFT/198b0ba90b1487e46940d1f16571b9c0 to your computer and use it in GitHub Desktop.
Demos comparing Windows PowerShell and PowerShell Core 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Side-by-side | |
## Use PSCore6 w/ elevation | |
Invoke-WebRequest https://github.com/PowerShell/PowerShell/releases/download/v6.1.0/PowerShell-6.1.0-win-x64.zip -OutFile pwsh61.zip | |
Unblock-File pwsh61.zip | |
Expand-Archive pwsh61.zip | |
## PowerShell.exe vs Pwsh.exe | |
'$psversiontable' > demo.ps1 | |
Powershell -c .\demo.ps1 | |
Pwsh -c .\demo.ps1 | |
## Performance | |
### ThreadJobs | |
Measure-Command { 1..10 | % { Start-Job { 1+1 } }; Get-Job | Wait-Job } | |
Measure-Command { 1..10 | % { Start-ThreadJob { 1+1 } }; Get-Job | Wait-Job } | |
### Write-Progress | |
#### Windows PowerShell | |
measure-command { Invoke-WebRequest https://github.com/PowerShell/PowerShell/releases/download/v6.1.0/PowerShell-6.1.0-win-x64.zip -OutFile pwsh1.zip } | |
#### PSCore 6 | |
measure-command { Invoke-WebRequest https://github.com/PowerShell/PowerShell/releases/download/v6.1.0/PowerShell-6.1.0-win-x64.zip -OutFile pwsh2.zip } | |
### .NET Core 2.1 | |
Invoke-WebRequest https://gist.githubusercontent.com/SteveL-MSFT/4907fc0d50025a784c787f64857b34f8/raw/92d30de7034ee39261c5ecfd3ef924c065579051/base64.ps1 -OutFile .\base64.ps1 | |
Measure-Command { .\base64.ps1 } | |
### Group-Object | |
Measure-Command { 1..10000 | % {Get-Random -Minimum 1 -Maximum 1000} | Group-Object } | |
### Sort-Object | |
Measure-Command { 1..10000 | % {Get-Random -Minimum 1 -Maximum 1000} | Sort-Object } | |
### Import-Csv | |
$csv = get-process | convertto-csv; 1..5 | % { $csv += $csv }; $csv > ./process.csv | |
Get-Content .\process.csv | Measure-Object | |
Measure-Command { Import-Csv .\process.csv } | |
## Cmdlet improvments | |
### Update-Help without elevation | |
Update-Help Microsoft.PowerShell.Management | |
### Parent Process | |
get-process | ? { $_.parent } | Select-Object ProcessName, Parent | |
## Webcmdlets | |
### Getting response headers with Invoke-RestMethod | |
$r = Invoke-RestMethod https://api.github.com/repos/PowerShell/PowerShell/issues -ResponseHeadersVariable h | |
$h | |
### Link header pagination | |
$i = Invoke-RestMethod https://api.github.com/repos/PowerShell/PowerShell/issues | |
$i.count | |
$j = Invoke-RestMethod https://api.github.com/repos/PowerShell/PowerShell/issues -FollowRelLink -MaximumFollowRelLink 3 | |
$j.count | |
$j.title.count | |
### Easy OAuth | |
$token = get-content ./token.txt | ConvertTo-SecureString -AsPlainText -Force | |
$r = Invoke-RestMethod https://api.github.com/repos/PowerShell/PowerShell/issues -Authentication OAuth -Token $token | |
## JSON cmdlets | |
### Formatting improvement | |
get-module psreadline | ConvertTo-Json | |
### -AsHashTable | |
'{ "" : "Test" }' | ConvertFrom-Json | |
### Roundtrip | |
'[ { "a" : "test" } ]' | ConvertFrom-Json | ConvertTo-Json | |
## Interactive console | |
### PSReadLine 2.0.0 Menu Complete | |
Get-Process - | |
[System.Diagnostics.Process]:: | |
### Set-Location | |
cd $PSHOME | |
cd - | |
### Markdown rendering | |
Show-Markdown -Path ..\repos\PowerShell\README.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment