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 |
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
# Single script for Windows PowerShell and PowerShell Core | |
## Use PSEdition | |
@' | |
if ($PSVersionTable.PSEdition -eq "Core") | |
{ "PowerShell Core!" } | |
else | |
{ "Windows PowerShell!" } | |
'@ > both.ps1 |
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
# Define the PS code to embed in the XML below here. | |
$sb = { | |
# Make sure we control the specific strict mode in effect. | |
# (The strict-mode setting is inherited from the parent scope.) | |
Set-StrictMode -Version 1 | |
# Save the error record at hand as well as its invocation info. | |
$err = $_ | |
$myInv = $err.InvocationInfo |
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
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Preview" |
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
@" | |
class foo | |
{ | |
[string] static bar([string] $text) | |
{ | |
return $text | |
} | |
} | |
"@ > class.psm1 |
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
# PowerShell remoting over SSH | |
## Configuring Windows | |
### Install SSHD as Feature on Demand | |
### Modify sshd_config for powershell subsystem | |
## SSH remoting | |
ssh –l user@domain computer |
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
$num = 50 | |
$ps = @("powershell.exe", "C:\Program Files\PowerShell\6\pwsh.exe", "C:\Program Files\PowerShell\7-preview\pwsh.exe") | |
$ps | ForEach-Object { | |
$thisps = $_ | |
$psv = & $thisps -nop -c '$psv = $psversiontable.gitcommitid; if ($psv -eq $null) { $psv = $psversiontable.psversion.tostring() }; $psv' | |
[int]$i = 0 | |
1..$num | ForEach-Object { | |
$i += (Measure-Command { | |
& $thisps -nop -c exit | |
}).TotalMilliseconds |
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
add-type -AssemblyName presentationframework | |
$xaml = @" | |
<Window | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
x:Name="Window" Title="Initial Window" WindowStartupLocation = "CenterScreen" | |
Width = "400" Height = "300" ShowInTaskbar = "True"> | |
</Window> | |
"@ |
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
nal w write-host | |
$d='First','Second','Third','Fourth','Fifth','Sixth','Seventh','Eighth','Ninth','Tenth','Eleventh','Twelfth',"A Partridge in a Pear Tree.`n",'Two Turtle Doves, and','Three French Hens,','Four Calling Birds,','Five Gold Rings,','Six Geese-a-Laying,','Seven Swans-a-Swimming,','Eight Maids-a-Milking,','Nine Ladies Dancing,','Ten Lords-a-Leaping,','Eleven Pipers Piping,','Twelve Drummers Drumming,' | |
$l="On the % day of Christmas`nMy true love sent to me" | |
0..11|%{w $l.Replace("%",$d[$_]) | |
$_..0|%{w $d[$_+12]}} |
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
1..100|%{$_%15?$_%3?$_%5?$_ :'Buzz':'Fizz':'FizzBuzz'|Write-Host} |
OlderNewer