Skip to content

Instantly share code, notes, and snippets.

View trackd's full-sized avatar

Andree Renneus trackd

  • 14:26 (UTC +02:00)
View GitHub Profile
@jborean93
jborean93 / New-ScheduledTaskSession.ps1
Last active September 6, 2024 11:19
Creates a PSSession that targets a scheduled task process
# Copyright: (c) 2024, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function New-ScheduledTaskSession {
<#
.SYNOPSIS
Creates a PSSession for a process running as a scheduled task.
.DESCRIPTION
Creates a PSSession that can be used to run code inside a scheduled task
@JustinGrote
JustinGrote / README.MD
Last active September 6, 2024 04:02
A proxy for Format-Table to apply the resultant view or save it as a format definition

TypeFormat

This module provides an improved Format-Table that lets you persist the resultant Format-Table view either to the current session or to a .ps1xml formatting file.

This module requires PowerShell 7.2+, however the generated XML format files can be used with earlier versions.

Quick Start

PS> Get-Date
@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
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
@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.

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'
}
@Jaykul
Jaykul / About Batch and PowerShell.md
Last active July 28, 2024 04:33
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
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);