Skip to content

Instantly share code, notes, and snippets.

@elonmallin
elonmallin / Group-ConsecutiveNumbers.ps1
Last active November 7, 2022 09:27
Powershell script to group consecutive numbers
function Group-ConsecutiveNumbers {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline, Mandatory, Position=0)]
$number
)
begin { $numbers = @() }
process { $numbers += $number }
end {
@elonmallin
elonmallin / docker-in-windows-container.ps1
Last active October 26, 2022 09:17
Docker (mounted from host) in docker for windows containers
docker run --rm -it --volume //./pipe/docker_engine://./pipe/docker_engine --mount type=bind,source="C:\Program Files\Docker",destination="C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps" --entrypoint=powershell mcr.microsoft.com/windows/servercore:ltsc2019 docker --version
@elonmallin
elonmallin / ssh-copy-id.ps1
Last active November 5, 2024 06:54
One-liner ssh-keygen and ssh-copy-id for Windows powershell
ssh-keygen && cat $env:userprofile/.ssh/id_rsa.pub | ssh user@linuxserver 'cat >> .ssh/authorized_keys'
@elonmallin
elonmallin / conditional-ternary-operator.psm1
Created September 7, 2018 08:44
Adds the conditional ternary operator from C# to Powershell (As close as we get anyway)
<#
Adds the conditional ternary operator.
Use e.g:
`$Color = $Settings.HasColor |?: $Settings.Color "blue"`
#>
function ConditionalTernary {
param (
[Parameter(ValueFromPipeline=$true)]$Value,
@elonmallin
elonmallin / null-coalesc-operator.psm1
Last active September 7, 2018 08:43
Adds the null coalesc operator from C# to Powershell (As close as we get anyway)
<#
Adds the null coalescing operator.
Use e.g:
`$Color = $Settings.Color |?? "blue"`
#>
function NullCoalesc {
param (
[Parameter(ValueFromPipeline=$true)]$Value,