Skip to content

Instantly share code, notes, and snippets.

View santisq's full-sized avatar

Santiago Squarzon santisq

View GitHub Profile

How do I do this thing?

I'm not aware of how to use Google, how do I do this basic thing in Language X?

tagged coding, question

edited by Grammar Nazi (2.5M), asked by 1337z0r (2)

Answer 1 (12)

@indented-automation
indented-automation / ActiveDirectory.md
Last active February 7, 2024 16:59
Active Directory

A small collection specialised scripts for Active Directory.

Includes:

  • Compare-ADMemberOf
  • Get-ADSystemInfo
  • Get-GroupMemberTree
  • Get-LdapObject
  • Get-MemberOfTree
  • Test-LdapSslConnection
@indented-automation
indented-automation / Get-FileEncoding.ps1
Last active November 1, 2022 19:56
Signature-based encoding detection
using namespace System.Collections.Generic; using namespace System.Linq
function Get-FileEncoding {
<#
.SYNOPSIS
Attempt to determine a file type based on a BOM or file header.
.DESCRIPTION
This script attempts to determine file types based on a byte sequence at the beginning of the file.
If an identifiable byte sequence is not present the file type cannot be determined using this method.
@mklement0
mklement0 / Time-Command.ps1
Last active December 18, 2024 07:42
PowerShell function that times the execution of one or more commands, averaged over a specifiable number of runs.
<#
Prerequisites: PowerShell v5.1 and above (verified; may also work in earlier versions)
License: MIT
Author: Michael Klement <[email protected]>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/9e1f13978620b09ab2d15da5535d1b27/raw/Time-Command.ps1 | iex
@indented-automation
indented-automation / Clean-File-Demo.ps1
Last active June 16, 2022 14:33
Removes trailing null data from the end of a file
$Path = 'c:\temp\test.long'
$content = [Byte[]]::new(50MB)
[Array]::Copy(
[Byte[]][Char[]]'Hello world',
0,
$content,
10,
11
)
@IISResetMe
IISResetMe / ConvertFrom-EventLogRecord.ps1
Last active October 23, 2024 15:53
Convert EventData fields from windows event log records to objects
function ConvertFrom-EventLogRecord
{
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[System.Diagnostics.Eventing.Reader.EventLogRecord[]]
$InputEvent,
[Parameter(Mandatory=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[string[]]
@SeeminglyScience
SeeminglyScience / Enter-PSSessionWithEdit.ps1
Last active May 4, 2023 03:27
Proof of concept for "psedit" working outside of PSES.
function Enter-PSSessionWithEdit {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $ComputerName
)
end {
$enterEventName = 'RemoteSessionEditor.Enter'
if (-not $Host.Runspace.Events.GetEventSubscribers($enterEventName)) {
@Jaykul
Jaykul / About CommandNotFoundAction.md
Last active June 26, 2024 12:23
Helpfully handling Command Not Found in PowerShell

Helpfully handling Command Not Found in PowerShell

About CommandNotFoundAction

In PowerShell there is a callback ("Action") that is called when a command lookup fails through normal means. The purpose of this callback is to allow you to add your own command-resolution, and there are a lot of community hacks out there already:

Community Implementations

  • You could add support for new command types, like
using namespace System.Net.Sockets; using namespace System.IO
function Watch-StarWars {
[CmdletBinding()]
param ( )
try {
$tcpClient = [TcpClient]::new()
$tcpClient.Connect('towel.blinkenlights.nl', 23)
function Measure-ChildItem {
<#
.SYNOPSIS
Recursively measures the size of a directory.
.DESCRIPTION
Recursively measures the size of a directory.
Measure-ChildItem uses win32 functions, returning a minimal amount of information to gain speed. Once started, the operation cannot be interrupted by using Control and C. The more items present in a directory structure the longer this command will take.
This command supports paths longer than 260 characters.