Skip to content

Instantly share code, notes, and snippets.

@codekaizen
codekaizen / Optimize-PSReadLineHistory.ps1
Created December 1, 2025 19:00 — forked from jdhitsolutions/Optimize-PSReadLineHistory.ps1
A PowerShell command to trim the command history file used by PSReadline
#requires -version 5.0
#requires -module PSReadline
Function Optimize-PSReadLineHistory {
<#
.SYNOPSIS
Optimize the PSReadline history file
.DESCRIPTION
The PSReadline module can maintain a persistent command-line history. However, there are no provisions for managing the file. When the file gets very large, performance starting PowerShell can be affected. This command will trim the history file to a specified length as well as removing any duplicate entries.
.PARAMETER MaximumLineCount
@codekaizen
codekaizen / powershellAPI.md
Created November 22, 2025 00:23 — forked from rjmholt/powershellAPI.md
Using the PowerShell API

Using the PowerShell .NET API

There are a number cases where it's desirable to call PowerShell from another .NET language, particularly from C#. The two main classes of scenario here are:

  • Running PowerShell code or reusing PowerShell commands from a cmdlet or module.
  • Using PowerShell from a standalone .NET application, usually by hosting a fresh instance of PowerShell

Both use cases have a largely similar usage pattern,

@codekaizen
codekaizen / RaspberryPi4-qemu.md
Created October 15, 2025 16:42 — forked from cGandom/RaspberryPi4-qemu.md
Emulating Raspberry Pi 4 with Qemu

Emulating Raspberry Pi 4 with Qemu

Just a quick update before we dive in: what we're actually doing here is running Raspberry Pi OS (64-bit) on a QEMU virtual ARM setup. This isn't full-blown hardware emulation of the Raspberry Pi 4, but more about creating a virtual environment for the OS. It doesn't mimic all the specific hardware features of the Pi 4, but it's pretty useful and great for general testing. I turned to this solution mainly to extract a modified sysroot from the Raspberry Pi OS, something not readily available in other resources. For those looking into detailed emulation of the actual Raspberry Pi 4's hardware in QEMU, check out this link for the latest updates: https://gitlab.com/qemu-project/qemu/-/issues/1208.

Hope it helps! :D

Shortcomings: No GUI yet, only console.

Steps

<#
.SYNOPSIS
BoxStarter script to configure Windows 10 development PC.
.DESCRIPTION
You might need to set:
Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy Bypass
@codekaizen
codekaizen / package-full.ps1
Created August 19, 2023 17:19 — forked from KZeronimo/package-full.ps1
Winget based Boxstarter Script - Full - Windows 10/11
# Set TLS 1.2
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
# Import Choco Install-*
Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1" -Force
# Set up choco cache location to work around Boxstarter Issue 241
$chocoCache = (Join-Path ([Environment]::GetEnvironmentVariable("LocalAppData")) "Temp\ChocoCache")
New-Item -Path $chocoCache -ItemType directory -Force
# Remove *.tmp from the choco cache directory so the ad-hoc package installs using Install-ChocolateyPackage behave idempotently - this is a hack
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
}
#Import-Module PSColors
#Import-Module posh-git
Import-Module -Name Terminal-Icons
@codekaizen
codekaizen / wttr.in for PowerShell
Created August 16, 2023 12:46 — forked from 9999years/wttr.in for PowerShell
How to enable wttr.in in a PowerShell console
<#
.DESCRIPTION
Fetches wttr.in for a terminal weather report.
.LINK
http://stknohg.hatenablog.jp/entry/2016/02/22/195644
.LINK
http://www.nivot.org/blog/post/2016/02/04/Windows-10-TH2-(v1511)-Console-Host-Enhancements
@codekaizen
codekaizen / git-notes.md
Created August 16, 2023 11:02 — forked from topheman/git-notes.md
Git notes cheat sheet
@codekaizen
codekaizen / TaskJob.cs
Created August 5, 2023 03:56 — forked from Stroniax/TaskJob.cs
A PowerShell Job wrapper for System.Threading.Tasks.Task to bridge the gap between asynchronous operations in C# and PowerShell.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
namespace Casion.PowerShell
{
/// <summary>
@codekaizen
codekaizen / CiscoVPNAutoLogin.ps1
Created August 2, 2023 07:36 — forked from fergie/CiscoVPNAutoLogin.ps1
PowerShell script to automate the Cisco AnyConnect SSL VPN client on Windows
# Source www.cze.cz
# This script is tested with "Cisco AnyConnect Secure Mobility Client version 3.0.5080"
# Run using %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\CiscoVPNAutoLogin.ps1"
# VPN connection details
[string]$CiscoVPNHost = "vpn.example.com"
[string]$Login = "username"
[string]$Password = "password"
[string]$vpncliAbsolutePath = 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe'