Skip to content

Instantly share code, notes, and snippets.

View santisq's full-sized avatar

Santiago Squarzon santisq

View GitHub Profile
@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 ($_) {
@jborean93
jborean93 / Get-ServiceCertStore.ps1
Created March 2, 2021 04:42
Opens an X509 store for an NT Service account
# Copyright: (c) 2021, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function Get-ServiceCertStore {
<#
.SYNOPSIS
Open an X509 store to a service account.
.DESCRIPTION
Opens an X509 store to the NT SERVICE account specified. The X509 store can be used to then add/remove/enumerate
@IISResetMe
IISResetMe / MagicNumber.class.ps1
Created December 19, 2020 21:18
ECMA-335 SpecialName-based operator overloading in PowerShell classes
class MagicNumber
{
hidden [int] $_value
MagicNumber([int]$value)
{
$this._value = $value
}
# ECMA-335 I.10.3.2
@vexx32
vexx32 / PowershellLoopBehavior.md
Last active November 15, 2024 18:59 — forked from JustinGrote/PowershellLoopBehavior.md
Reference Table for Loop Behavior in Powershell
Loop Return Continue Break
Normal Expectation Exit Scope Next Item Exit Loop
.foreach{} Next Item Break Scopes / Next Item of Parent Loop Break Scopes / Exit Parent Loop
foreach ($y in $x) Exit Scope Next Item Exit Loop
for ($i;$i -lt 5;$i++) Exit Scope Next Item Exit Loop
Foreach-Object -InputObject @() Next Item Break Scopes / Next Item of Parent Loop Break Scopes / Exit Parent Loop
Switch Exit Scope Next Item Exit Switch
While
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,
@jborean93
jborean93 / Get-FtpFile.ps1
Last active October 19, 2022 00:20
Gets a file from an FTP(S) server
# Copyright: (c) 2020, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function Get-FtpFile {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[System.Uri]
[Alias('Uri')]
$FtpUrl,
function Get-XmlFileTreeAppend
{
param(
[Parameter(ParameterSetName='Path', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[string[]]
${Path},
[Parameter(ParameterSetName='LiteralPath', Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Alias('PSPath')]
[string[]]
function Test-RpcPort {
<#
.SYNOPSIS
Enumerates and tests connectivity to the RPC ports on the target server.
.DESCRIPTION
Enumerates and tests connectivity to the RPC ports on the target server.
Rebuilt from https://gallery.technet.microsoft.com/Test-RPC-Testing-RPC-4396fcda
#>
@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.
@jborean93
jborean93 / Invoke-WithImpersonation.ps1
Last active January 20, 2025 01:30
Invoke a scriptblock in powershell with impersonation
# Copyright: (c) 2020, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function Invoke-WithImpersonation {
<#
.SYNOPSIS
Invoke a scriptblock as another user.
.DESCRIPTION
Invoke a scriptblock and run it in the context of another user as supplied by -Credential.