Skip to content

Instantly share code, notes, and snippets.

@rgl
rgl / Start-WrappedProcess.ps1
Created January 6, 2018 08:20
Run a process and capture its stdout and stderr to a file
# converts/escapes a string to a command line argument.
function ConvertTo-CommandLineArgument {
# Normally, an Windows application (.NET applications too) parses
# their command line using the CommandLineToArgvW function. Which has
# some peculiar rules.
# See http://msdn.microsoft.com/en-us/library/bb776391(VS.85).aspx
#
# TODO how about backslashes? there seems to be a weird interaction
# between backslahses and double quotes...
process {
@rgl
rgl / export-windows-ca-certificates.ps1
Last active November 1, 2017 10:44
export-windows-ca-certificates
# dump all the windows trusted roots into a ca file.
$pems = New-Object System.Text.StringBuilder
Get-ChildItem Cert:\LocalMachine\Root | ForEach-Object {
# $_ is-a System.Security.Cryptography.X509Certificates.X509Certificate2
Write-Host "Exporting the $($_.Issuer) certificate..."
[void]$pems.AppendLine('-----BEGIN CERTIFICATE-----')
[void]$pems.AppendLine(
[Convert]::ToBase64String(
$_.Export('Cert'),
'InsertLineBreaks'));
@rgl
rgl / show-youtube-playlist.md
Created October 22, 2017 20:27
show a youtube playlist metadata

Download the youtube-dl binary:

wget -q https://github.com/rg3/youtube-dl/releases/download/2017.10.20/youtube-dl
chmod +x youtube-dl
./youtube-dl --version

Download the playlist metadata, prefering audio:

@rgl
rgl / TlsServerCertificateChainExporter.ps1
Created May 17, 2017 20:49
Export a given server certificate chain into local independent files
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
trap {
Write-Output "ERROR: $_"
Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
Write-Output (($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1')
Exit 1
}
Add-Type @'
@rgl
rgl / whoami.ps1
Created May 1, 2017 20:22
whoami for Windows Nano Server
# whoami for Nano Server.
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
trap {
Write-Output "ERROR: $_"
Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
Write-Output (($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1')
@rgl
rgl / windows-update-history.ps1
Created April 16, 2017 14:29
List Windows update history
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
trap {
Write-Output "ERROR: $_"
Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
Exit 1
}
@rgl
rgl / android-sdk-ubuntu.sh
Last active February 20, 2022 08:11
install android sdk on ubuntu
#
# install git.
apt-get install -y git-core
#
# install the Android Sdk.
@rgl
rgl / notepadplusplus.ps1
Created January 20, 2017 11:54
replace notepad with notepad++
choco install -y notepadplusplus.install
# replace notepad with notepad++.
# see http://sbs.seandaniel.com/2009/03/replacing-windows-applications-safe-way.html
[IO.File]::WriteAllText(
'C:\Program Files\Notepad++\launch.js',
@'
var cmd = '"C:\\Program Files\\Notepad++\\notepad++.exe"';
for (var n = 1; n < WSH.Arguments.Length; ++n) {
cmd += ' "' + WSH.Arguments.Item(n) + '"'; // TODO do proper escaping.
#!/bin/bash
# see http://www.syslinux.org/wiki/index.php?title=Filesystem
# see https://wiki.archlinux.org/index.php/syslinux
# NB on Arch Linux install with pacman -S dosfstools.
set -eux
disk_file=disk.img
disk_device=/dev/nbd0
disk_partition_device=/dev/nbd0p1
@rgl
rgl / Remove-VirtualBoxHostOnlyNetworkInterfacesFromWindowsFirewall.ps1
Created October 22, 2016 23:42
Remove all the VirtualBox Host-Only network interfaces from the Windows firewall
# exclude the VirtualBox network interfaces from the Windows Firewall.
Set-NetFirewallProfile -DisabledInterfaceAliases (Get-NetAdapter `
| Where-Object {$_.Virtual} `
| Where-Object {$_.DriverFileName -like 'VBox*.sys'} `
| ForEach-Object { $_.InterfaceAlias })