Skip to content

Instantly share code, notes, and snippets.

View mattcargile's full-sized avatar

Matt Cargile mattcargile

  • Baton Rouge, LA
View GitHub Profile
@Jaykul
Jaykul / Grouping.psm1
Created April 14, 2023 22:18
Expand and Group objects when they have (or could be deduped with) a single array property
filter Expand-Property {
<#
.SYNOPSIS
Expands an array property, creating a duplicate object for each value
.EXAMPLE
[PSCustomObject]@{ Name = "A"; Value = @(1,2,3) } | Expand-Property Value
Name Value
---- -----
A 1
@romero126
romero126 / Import-ModuleManually
Created July 19, 2023 18:20
Import-Module Manually
function Import-ModuleManually {
param(
[Parameter(Mandatory=$true)]
[string]$Module,
[Parameter(Mandatory=$false)]
[switch]$Force
)
$moduleExists = Get-Module -Name $Module -All
@jborean93
jborean93 / NoGui.ps1
Last active April 12, 2025 19:01
Generates an exe called NoGui.exe that can spawn a hidden windows
<#
NOTE: Must be run in Windows PowerShell (5.1), PowerShell (7+) cannot create standalone exes.
This is designed to create a simple exe that can be used to spawn any console
application with a hidden Window. As NoGui.exe is a GUI executable it won't
spawn with an associated console window and can be used to then create a new
process with a hidden console window with the arguments it was created with.
By default, NoGui will spawn the child process with same stdio handles as
@santisq
santisq / method1.ps1
Last active September 16, 2024 21:43
bind default values to `$PSBoundParameters`
& {
[CmdletBinding(DefaultParameterSetName = 'A')]
param(
[Parameter(ParameterSetName = 'A')]
$ParamA = 'A',
[Parameter(ParameterSetName = 'B')]
$ParamB = 'B',
[Parameter(Mandatory)]
$ParamBoth
)
function Get-BoundParameters {
<#
.DESCRIPTION
Get-BoundParameters is a helper function that returns a hashtable of the bound parameters of the calling function.
difference between $PSBoundParameters is that it gets default value from param block as well.
.PARAMETER IncludeCommon
include the common parameters
@jborean93
jborean93 / Get-FileProcess.ps1
Created May 30, 2024 23:18
Gets the process ids that has the requested file(s) opened
# Copyright: (c) 2024, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
#Requires -Module Ctypes
#Requires -Version 7.3
Function Get-FileProcess {
<#
.SYNOPSIS
Get the process that has opened the requested file.
@jborean93
jborean93 / Split-ExeArgument.ps1
Last active August 19, 2024 19:40
Splits the input string using the Win32 argument splitter
# Copyright: (c) 2024, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
#Requires -Module Ctypes
Function Split-ExeArgument {
[OutputType([string])]
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)]
# Here's tiny clipboard sugar for a profile
# context: there was a thread about creating a custom clipboard uri, and clipboard cmdlets
# <https://discord.com/channels/180528040881815552/447476117629304853/1260981998479081562>
Import-Module Pansies
# It's nice to get a confirmation that your clip was saved
$PSDefaultParameterValues['Set-ClipBoard:PassThru'] = $true
Set-alias 'cl' 'Set-ClipBoard' # 'sc' already exists
Set-Alias 'gcl' 'Get-Clipboard'
@trackd
trackd / Show-Object.md
Last active October 28, 2024 22:56
Show-Object

this is just me playing around with [ClassExplorer.Internal._Format] class to make things pretty.
obviously there is a hard requirement for the module ClassExplorer

also note the Internal in the name, this could probably break at any time.

Show-Object

experimental thing.. :)

@jborean93
jborean93 / New-ScheduledTaskSession.ps1
Last active April 7, 2025 18:56
Creates a PSSession that targets a scheduled task process
# Copyright: (c) 2024, Jordan Borean (@jborean93) <[email protected]>
# 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