Skip to content

Instantly share code, notes, and snippets.

View mattcargile's full-sized avatar

Matt Cargile mattcargile

  • Baton Rouge, LA
View GitHub Profile
@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
@cdhunt
cdhunt / cdhunt.format.ps1xml
Created April 8, 2021 13:13
Combing FileSystemTypes formats from Powershell-Humanizer and Termincal-Icons
<?xml version="1.0" encoding="utf-8" ?>
<!-- Based on the format.ps1xml file from DirColors
https://github.com/DHowett/DirColors -->
<Configuration>
<SelectionSets>
<SelectionSet>
<Name>FileSystemTypes</Name>
<Types>
<TypeName>System.IO.DirectoryInfo</TypeName>
@mklement0
mklement0 / Invoke-WithEncoding.ps1
Last active September 7, 2023 18:59
PowerShell function for invoking native (external) programs with a specified character encoding
<#
Prerequisites: PowerShell v3+
License: MIT
Author: Michael Klement <[email protected]>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/ef57aea441ea8bd43387a7d7edfc6c19/raw/Invoke-WithEncoding.ps1 | iex
@keyboardcrunch
keyboardcrunch / S1ACompliance.ps1
Created March 17, 2021 14:14
SentinelOne Agent compliance script
$Installed = Get-WmiObject -Class Win32Reg_AddRemovePrograms | Where-Object { $_.DisplayName -eq "Sentinel Agent" }
If ( -Not $Installed ) {
# Sentinel Agent not installed/missing.
Return $false
} Else {
$Version = $Installed.Version
$SentinelCtl = "C:\Program Files\SentinelOne\Sentinel Agent $Version\SentinelCtl.exe"
$Status = & $SentinelCtl "status"