Skip to content

Instantly share code, notes, and snippets.

Set-PSReadLineKeyHandler -Key 'Alt+a' -ScriptBlock {
param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$tokens = $null
$ast = $null
$parseErrors = $null
@ThePSAdmin
ThePSAdmin / kubectlalias.ps1
Last active July 1, 2020 07:52
Kubectl aliases for pwsh
New-Alias -Name k -Value kubectl
function kaf(){& kubectl apply -f $args}
function kca(){& kubectl $args --all-namespaces}
function kccc(){& kubectl config current-context $args}
function kcdc(){& kubectl config delete-context $args}
function kcgc(){& kubectl config get-contexts $args}
function kcn(){& kubectl config set-context $(kubectl config current-context) --namespace $args}
function kcp(){& kubectl cp $args}
function kcsc(){& kubectl config set-context $args}
function kcuc(){& kubectl config use-context $args}
((((99..1)+'no more')|%{}{$y,$a=" on the wall"," bottle$(,'s'[$_-eq1]) of beer"
"Take one down and pass it around, $_$a$y.`n"
"$_$a$y, $_$a."-replace'^n',"N"}{"Go to the store and buy some more, 99$a$y."})[1..200])|write-host
{
"command": "splitHorizontal",
"keys": [
"ctrl+shift+h"
]
},
{
"command": "splitVertical",
"keys": [
@ThePSAdmin
ThePSAdmin / ReadMe.md
Last active March 2, 2023 00:25 — forked from Jaykul/ReadMe.md
Kestrel in PowerShell

Trying to get Kestrel to work in PowerShell

This works, sort-of, but for some reason it won't actually serve pages. I get nothing but "The connection was reset" or "can't reach this page"

Before you can run Start-Kestrel, you need to download a bunch of assemblies, and since my example is just trying to serve files, you'll need a file or two...

From an empty folder where you're going to put Start-Kestrel.ps1 we need to install a thousand DLLs or so...

Install-Package Microsoft.AspNetCore.App -ProviderName NuGet -Destination bin -Source nuget.org -Force
$classFolder = "c:\dev\myproject\classes"
$files = Get-ChildItem $classFolder -Filter *.ps1 -Recurse
$typesList = [System.Collections.Generic.List[PsObject]]::New()
foreach ($file in $files) {
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$null, [ref]$null)
$typeNames = $ast.FindAll( {$args[0] -is [System.Management.Automation.Language.TypeDefinitionAst]}, $true) | Select-Object -ExpandProperty Name
$typesList.Add([PSCustomObject]@{
FilePath = $file.FullName
@ThePSAdmin
ThePSAdmin / powershell.json
Created January 12, 2018 13:14
VSCode snippets for powershell
{
"Write Verbose": {
"prefix": "wv",
"body": [
"Write-Verbose \"[${TM_FILENAME/(.*)\\..+$/$1/}] $0\""
],
"description": "Write-Verbose with base name of filename."
},