Skip to content

Instantly share code, notes, and snippets.

View mattcargile's full-sized avatar

Matt Cargile mattcargile

  • Baton Rouge, LA
View GitHub Profile
function Get-ComputerSession {
[CmdletBinding()]
param(
# The computer name to get the current sessions from. Use an empty string for local machine.
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[AllowEmptyString()]
[String]
$ComputerName,
# Flattens the output
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 / win_powershell_ssh.ps1
Last active May 9, 2025 11:30
Windows PowerShell SSH Remoting Stub
<#
.SYNOPSIS
Windows PowerShell SSH Server Subsystem Shim.
.DESCRIPTION
Used as a basic wrapper for Windows PowerShell that allows it to be used as a target for SSH based remoting sessions.
This allows a PowerShell client to target a Windows host through SSH without having PowerShell 7 installed.
.NOTES
This is experimental and used as a POC.
@jborean93
jborean93 / PSClassSplat.ps1
Last active December 5, 2023 10:25
Example on how to use a class as a PowerShell splat value
class SplatClass : System.Collections.IEnumerable {
SplatClass() {}
[System.Collections.IEnumerator] GetEnumerator() {
# This can be any hashtable stored or derived from the class. This is
# just an example
$params = @{
Path = '/tmp'
}
@jborean93
jborean93 / NetServiceAccount.ps1
Created February 2, 2022 00:44
APIS that wrap the LMAccess Net*ServiceAccount APIS for Managed Service Accounts
Add-Type -Namespace LmAccess -Name Native -MemberDefinition @'
[DllImport("Netapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "NetAddServiceAccount")]
private static extern int NativeNetAddServiceAccount(
IntPtr ServerName,
string AccountName,
IntPtr Password,
AddServiceFlags Flags);
/// <summary>Add a sMSA or gMSA to the current host.</summary>
/// <param name="accountName">The name of the MSA to install.</param>
@ninmonkey
ninmonkey / ExpandAlias.gif
Last active March 9, 2022 21:51
Custom PowerShell 7 PSReadLikeKeyHandlers.ps1
ExpandAlias.gif
@jborean93
jborean93 / Runas.ps1
Created June 2, 2021 20:27
Creates a process running as SYSTEM
. $PSScriptRoot\Start-ProcessEx.ps1
Add-Type -Namespace Runas -Name NativeMethods -UsingNamespace @(
'Microsoft.Win32.SafeHandles',
'System.ComponentModel',
'System.Security.Principal'
) -MemberDefinition @'
[DllImport("Advapi32.dll", EntryPoint = "DuplicateTokenEx", SetLastError = true)]
private static extern bool NativeDuplicateTokenEx(
SafeHandle hExistingToken,
@keyboardcrunch
keyboardcrunch / SentinelOne_SCCM_Compliance_and_Remediation.ps1
Last active January 9, 2023 22:19
Granular Configuration Manager Compliance and Remediation scripts for SentinelOne Agent
<# Check installation compliance #>
$Installed = Get-WmiObject -Class Win32Reg_AddRemovePrograms | Where-Object { $_.DisplayName -eq "Sentinel Agent" }
If ( -Not $Installed ) {
# Sentinel Agent not installed/missing.
Return $false
} Else {
Return $true
}
@jborean93
jborean93 / Get-ExtendedAttribute.ps1
Created April 14, 2021 22:26
Gets extended attributes for a file on an NTFS volume
# Copyright: (c) 2021, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
class EncodingTransformAttribute : Management.Automation.ArgumentTransformationAttribute {
[object] Transform([Management.Automation.EngineIntrinsics]$engineIntrinsics, [object]$InputData) {
$outputData = switch ($InputData) {
{ $_ -is [Text.Encoding] } { $_ }
{ $_ -is [string] } {
switch ($_) {
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
}
#Import-Module PSColors
#Import-Module posh-git
Import-Module -Name Terminal-Icons