Skip to content

Instantly share code, notes, and snippets.

View ckolumbus's full-sized avatar
🐧
Live, Love, Code

Chris Drexler ckolumbus

🐧
Live, Love, Code
View GitHub Profile
@Jaykul
Jaykul / About Batch and PowerShell.md
Last active January 24, 2024 05:27
Executable PowerShell (wrap a ps1 and name it cmd)

This is always my answer to all those "compile your .ps1" solutions that are floating around. Why would you wrap your PowerShell in an exe and some custom host?

Just paste this header on the top of your PowerShell script, and then before you share it, rename it with the .cmd extension. While you're writing, it's a nice syntax-highlighted PowerShell script, and when you rename it, *poof* it's double-clickable. Drop it in the PATH and you can execute it from the Run dialog or from PowerShell, batch, whatever.

Because there are still people around who actually use CMD, I've updated it to show how to handle passing parameters.

A couple of notes:

  1. It runs with ExecutionPolicy unrestricted because if you're still using CMD you probably haven't configured your ExecutionPolicy
  2. It uses -NoProfile to make sure the environment is the same on everyone's PC...
  3. It only creates function :: {} because that allows us to ignore the :: on the first line
@andrewmatveychuk
andrewmatveychuk / registerRepository.ps1
Last active July 17, 2023 18:27
Using Register-PackageSource to register a PowerShell repository
$patToken = $env:SYSTEM_ACCESSTOKEN | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($env:SYSTEM_ACCESSTOKEN, $patToken)
Register-PackageSource -ProviderName 'PowerShellGet' -Name <YOUR_REPOSITORY_NAME> -Location <REPOSITORY_LOCATION> -Credential $Credentials
Find-Module -Name 'YOUR_MODULE_NAME' -Credential $credential
Install-Module -Name 'YOUR_MODULE_NAME' -Credential $credential
@mamidenn
mamidenn / Import-LocalModule.ps1
Created March 16, 2020 10:25
Import PowerShell module without polluting environment
$name = psake
Save-Module -Name $name -Path .
Import-Module -Name .\$name
@strarsis
strarsis / howto.md
Last active July 8, 2024 08:27
KeeAgent (for KeePass) on Bash on Windows / WSL (2)

Update (March 2023) (Last checked: June 2024)

Side note: The latest edge build of KeeAgent plugin offers an option for creating a WSL compatible socket. This would be very handy. I already tried to use that socket, but the socket file is currently empty and ssh inside WSL 2 is unable to use it. This appears to be a very new, unreleased and unstable feature. I will follow the development of it and when it finally works (well, for me) I will update this HOWTO. But until then, please use the proven wsl-ssh-agent/npiperelay.exe approach below.

Thanks to the instructions for WSL 2 of the wsl-ssh-agent project, KeeAgent works great in WSL 2 now: https://github.com/rupor-github/wsl-ssh-agent#wsl-2-compatibility The approach uses minimal and well maintained tools.

Mini-changelog

  • (16.03.2024) Add: Ensure 7z and wslvar being available (thanks @johnzielke
using System.Collections.Concurrent;
using System.Reflection;
using System.Threading;
using System.Xml.Linq;
public void RunSimultaneously(params Action[] actions)
{
if (actions.Length == 0) return;
@ferventcoder
ferventcoder / NonAdmin.cmd
Last active July 21, 2024 18:14
Installing Software as a Non-Administrator Using Chocolatey
:: Pick one of these two files (cmd or ps1)
:: Set directory for installation - Chocolatey does not lock
:: down the directory if not the default
SET INSTALLDIR=c:\ProgramData\chocoportable
setx ChocolateyInstall %INSTALLDIR%
:: All install options - offline, proxy, etc at
:: https://chocolatey.org/install
@powershell -NoProfile -ExecutionPolicy Bypass -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET PATH="%PATH%;%INSTALLDIR%\bin"
@Tiberriver256
Tiberriver256 / PSWebServer.psm1
Last active March 6, 2024 03:49
Sample of making a simple webserver in PowerShell. If you have more complex needs checkout Pode (https://github.com/Badgerati/Pode) as a fully fledged PowerShell web server.
Function New-PSWebServer {
<#
.Synopsis
Creates a web server that will invoke PowerShell code based on routes being asked for by the client.
.Description
New-PSWebServer creates a web server. The web server is composed of a schema that defines the client's requests to routes where PowerShell code is executed.
Under the covers, New-PSWebServer uses the HTTPListener .NET class to execute powershell code as requested, retrieves the results and sends data back through the httplistener web server framework.