Skip to content

Instantly share code, notes, and snippets.

View mattcargile's full-sized avatar

Matt Cargile mattcargile

  • Baton Rouge, LA
View GitHub Profile
@JustinGrote
JustinGrote / Update-ModuleFast.ps1
Last active January 9, 2024 05:44
A faster implementation of Powershell's Update Module New Module check
throw 'This has moved to https://github.com/JustinGrote/ModuleFast'
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);
@IISResetMe
IISResetMe / BigIntRange.class.ps1
Created August 13, 2019 15:38
Lazy range generator for `[bigint]`
class BigIntRange : System.Collections.IEnumerable
{
[bigint]$from
[bigint]$to
[bool]$Descending
BigIntRange([bigint]$from,[bigint]$to)
{
$this.from = $from
@JustinGrote
JustinGrote / ModuleFast.ps1
Last active August 17, 2024 11:42
Bootstrap Script for a High Performance Module Installer
using namespace System.Net.Http
#requires -version 7.2
# This is the bootstrap script for Modules
[CmdletBinding(PositionalBinding = $false)]
param (
#Specify a specific release to use, otherwise 'latest' is used
[string]$Release = 'latest',
#Specify the user
[string]$User = 'JustinGrote',
#Specify the repo
@indented-automation
indented-automation / Split-DistinguishedName.ps1
Last active February 7, 2025 17:27
Split an AD DN into different parts
function Split-DistinguishedName {
<#
.SYNOPSIS
Split a distinguishedName into named pieces.
.DESCRIPTION
Split a distinguishedName into Name, ParentDN, ParentName, and DomainComponent.
.EXAMPLE
Split-DistinguishedName 'OU=somewhere,DC=domain,DC=com'
@jborean93
jborean93 / Get-SmbShareInfo.ps1
Created May 6, 2020 19:55
Enumerates shares on a remote host
# Copyright: (c) 2020, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function Get-SmbShareInfo {
<#
.SYNOPSIS
Enumerate shares on a remote host.
.DESCRIPTION
Enumerate shares on a remote host and returns the name, type, and special remark for those shares.
@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
@Jaykul
Jaykul / New-Hyperlink.ps1
Last active August 21, 2024 11:02 — forked from JustinGrote/Write-ANSIHyperlink.ps1
Powershell Function to create Terminal HyperLinks using ANSI Escape Sequences (Supported in Windows Terminal PREVIEW)
using namespace System.Management.Automation
# Use of StopUpstreamCommandsException is obviously not supported. Subject to breaking at any time.
function Select-FirstObject {
[Alias('first', 'top')]
[CmdletBinding(PositionalBinding = $false)]
param(
[Parameter(ValueFromPipeline)]
[psobject] $InputObject,
@Jaykul
Jaykul / Measure-CommandEx.ps1
Last active June 22, 2022 05:29
We need a better Measure-Command which can show averages
function Measure-CommandEx {
<#
.SYNOPSIS
A from-scratch approach to timing command execution using Stopwatch
#>
[CmdletBinding()]
param(
# The command to test (accepts value from pipeline)
[Parameter(ValueFromPipeline)]
[ScriptBlock[]]$Command,