Skip to content

Instantly share code, notes, and snippets.

View trackd's full-sized avatar

Andree Renneus trackd

  • 01:41 (UTC +02:00)
View GitHub Profile
using namespace System.Collections.Generic; using namespace System.Text
Add-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;
using System.Text;
public class WindowTools
{
public delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);
@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
class ConstrainedVariableInterpolation : System.Management.Automation.Language.AstVisitor {
hidden [Hashtable] $Property
[System.Collections.Generic.List[PSCustomObject]] $Result
hidden [System.Management.Automation.Language.Ast] $Ast
[System.Management.Automation.Language.AstVisitAction] CheckForPostAction([System.Management.Automation.Language.Ast] $ast, [System.Management.Automation.Language.AstVisitAction] $action)
{
throw 'CheckForPostAction not supported'
}
@jborean93
jborean93 / PSGet Publisher Checks.md
Last active April 15, 2024 23:53
Behaviour of signed PowerShell scripts

PSGet Code Signing

This is to try and document the behaviour around PowerShellGet/PSResourceGet code signing publisher behaviour.

Setup

The following code can be used to set up this scenario. This must be run as an administrator in Windows PowerShell.

Note: PowerShell uses implicit remoting for the New-SelfSignedCertificate which breaks the constains serialization. You must run this on Windows PowerShell.

using namespace System
using namespace System.Linq
using namespace System.Collections
using namespace System.Collections.Generic
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
using namespace System.Reflection
# Hey person reading this! Don't do this, alright? You'll have a bad time. ty
@ninmonkey
ninmonkey / Inspect Runes in Powershell.ps1
Last active January 15, 2024 12:20
Inspecting the codepoints, and runes of strings - Pwsh | Powershell
function inspectRunes {
<#
.synopsis
minimal sugar to see codepoints
.EXAMPLE
$Str1 = '🐒'
$str1 | inspectRunes.prof
#>
param(
# default will replace control chars to text. ie: You can pipe it safely
@JustinGrote
JustinGrote / EasyFormat.psm1
Last active July 15, 2024 08:39
A proxy for Format-Table to apply the resultant view or save it as a format definition
using namespace System.Management.Automation
using namespace System.Management.Automation.Runspaces
using namespace System.Collections
using namespace System.Collections.Generic
using namespace System.Text
using namespace System.Xml
using namespace System.IO
$ErrorActionPreference = 'Stop'
$SCRIPT:RunspaceFormats = [Runspace]::DefaultRunspace.InitialSessionState.Formats