Skip to content

Instantly share code, notes, and snippets.

View SteveL-MSFT's full-sized avatar

Steve Lee SteveL-MSFT

View GitHub Profile
@SteveL-MSFT
SteveL-MSFT / demo_winps_comparison.ps1
Last active October 17, 2018 10:32
Demos comparing Windows PowerShell and PowerShell Core 6
# 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
@SteveL-MSFT
SteveL-MSFT / demo_windows_compat.ps1
Last active October 17, 2018 10:48
Demos for Windows PowerShell compatibility with PowerShell Core 6
# Single script for Windows PowerShell and PowerShell Core
## Use PSEdition
@'
if ($PSVersionTable.PSEdition -eq "Core")
{ "PowerShell Core!" }
else
{ "Windows PowerShell!" }
'@ > both.ps1
@SteveL-MSFT
SteveL-MSFT / Update-ErrorFormat.ps1
Last active November 30, 2018 13:52
ErrorRecord Format
# 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
@SteveL-MSFT
SteveL-MSFT / install-pscore-preview.ps1
Created December 12, 2018 20:16
Install preview builds of PSCore6
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Preview"
@SteveL-MSFT
SteveL-MSFT / ModuleClass.ps1
Created January 26, 2019 02:32
Access class inside script module
@"
class foo
{
[string] static bar([string] $text)
{
return $text
}
}
"@ > class.psm1
@SteveL-MSFT
SteveL-MSFT / demo_os_agnostic.ps1
Last active February 23, 2019 17:59
Demos of writing OS agnostic PowerShell Core scripts
# 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
@SteveL-MSFT
SteveL-MSFT / perftest.ps1
Created October 18, 2019 22:29
Startup perf test
$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
@SteveL-MSFT
SteveL-MSFT / wpf.ps1
Created September 17, 2019 15:18
WPF Example
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>
"@
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]}}
1..100|%{$_%15?$_%3?$_%5?$_ :'Buzz':'Fizz':'FizzBuzz'|Write-Host}