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
using System; | |
using System.Runtime.InteropServices; | |
namespace myps | |
{ | |
public static class GetProcArgv | |
{ | |
private const int CTL_KERN = 1; | |
private const int KERN_ARGMAX = 8; | |
private const int KERN_PROCARGS2 = 49; |
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
$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
function Format-Table { | |
param([parameter(valuefrompipeline=$true)]$inputObject) | |
begin { | |
$objects = [System.Collections.Generic.List[PSObject]]::new() | |
} | |
process { | |
$objects += $inputObject | |
} |
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
$query = @" | |
query { | |
organization(login: "powershell") { | |
name | |
url | |
repository(name: "powershell") { | |
name | |
pullRequests(last: 20, states: [OPEN]) { | |
edges { | |
node { |
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
using namespace System.CommandLine.Rendering | |
add-type -AssemblyName ./System.CommandLine.Rendering.dll | |
$cs = [ContainerSpan]::new( | |
[StyleSpan]::UnderlinedOn(), | |
[ForegroundColorSpan]::Green(), | |
[BackgroundColorSpan]::Yellow(), | |
[ContentSpan]::new("hello"), | |
[StyleSpan]::UnderlinedOff() |
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} |
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
$parameters = @{ | |
Key = 'F7' | |
BriefDescription = 'ShowMatchingHistoryOcgv' | |
LongDescription = 'Show Matching History using Out-ConsoleGridView' | |
ScriptBlock = { | |
param($key, $arg) # The arguments are ignored in this example | |
$line = $null | |
$cursor = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) | |
$history = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems().CommandLine | Select-Object -Unique |
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
param($file) | |
$tokens = $null | |
$err = $null | |
$file = Resolve-Path $file | |
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file, [ref]$tokens, [ref]$err) | |
$commands = $ast.FindAll({$true},$true) | ? { $_ -is [System.Management.Automation.Language.CommandAst] } | % { $_.CommandElements[0].Value } | Sort-Object -Unique | |
$sources = [System.Collections.Generic.List[string]]::new() | |
$commands | % { |