Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jborean93 on github.
  • I am jborean93 (https://keybase.io/jborean93) on keybase.
  • I have a public key ASBK396SPyaXDgm1YsnDbsIuacm8LKPknZa0C4omPUU8SAo

To claim this, I am signing this object:

@jborean93
jborean93 / shadow-copy.ps1
Created March 20, 2019 01:22
Enumerate Shadow Copies and mount them
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @'
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool CreateSymbolicLinkW(
string lpSymlinkFileName,
string lpTargetFileName,
UInt32 dwFlags);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool RemoveDirectoryW(
@jborean93
jborean93 / shadow-copy-deviceiocontrol.ps1
Created March 20, 2019 01:44
Use DeviceIoControl to enumerate shadow copies
<#
This does not work due to the unsupported CTL_CODE used in DeviceIoControl
DeviceIoControl() get buffer size failed - Incorrect function (Win32 ErrorCode 1 - 0x00000001)
At C:\temp\enumerate_snapshots.ps1:145 char:1
+ Get-ShadowCopy -Path "\\localhost\c$"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-ShadowCopy
#>
@jborean93
jborean93 / Get-ProcessSessionStationAndDesktop.ps1
Last active May 3, 2019 09:34
Get process session, station, and desktop
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
namespace ProcessInfo
{
public class NativeMethods
{
[DllImport("User32.dll", SetLastError = true)]
public static extern bool CloseDesktop(
@jborean93
jborean93 / Install-ModuleNupkg.ps1
Last active June 13, 2019 22:32
Installs a PowerShell module from a Nupkg URI on systems that don't have PowerShellGet installed
# Copyright: (c) 2019, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
<#
The cmdlets in this script can be used to install a PowerShell module from a nupkg as well as some logic to get the
nupkg URI from either the PowerShell Gallery or a GitHub release asset. The PowerShell Gallery is the most reliable
function to use as a nupkg is guaranteed to be there and a GitHub release must have explicitly added the nupkg itself.
You can run this by doing:
@jborean93
jborean93 / Remove-LongPath.ps1
Last active August 8, 2019 23:23
Deletes files and folders that exceed max path
Add-Type -TypeDefinition @'
using Microsoft.Win32.SafeHandles;
using System;
using System.IO;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
namespace FileIO
{
public class NativeHelpers
@jborean93
jborean93 / PSRunas.psm1
Last active December 23, 2019 05:22
Quick and dirty PowerShell module that implements Start-Process using CreateProcessWithToken
# Copyright: (c) 2019, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
$pinvokeParams = @{
IgnoreWarnings = $true
WarningAction = 'Ignore'
TypeDefinition = @'
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections;
@jborean93
jborean93 / Get-ItemWithCredential.ps1
Created February 3, 2020 03:21
Basic example of how to access network paths with custom credentials
# Copyright: (c) 2020, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Add-Type -Namespace LogonUtil -Name NativeMethods -MemberDefinition @'
[DllImport("Kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(
IntPtr hObject);
[DllImport("Advapi32.dll", SetLastError = true)]
public static extern bool ImpersonateLoggedOnUser(
@jborean93
jborean93 / shippable-target-time.py
Last active March 3, 2020 17:52
Simple script that turns the test.json output of https://github.com/ansible/ansible/blob/devel/hacking/shippable/download.py to a easy to view table of test target runtimes
#!/usr/bin/env python
import json
import operator
import os
def get_raw_test_targets(test_path):
with open(test_path, mode='rb') as fd:
test_info = json.loads(fd.read().decode('utf-8'))
@jborean93
jborean93 / ansible_migrate.py
Created March 11, 2020 04:59
Python script to help with migrating issues and PRs from ansible/ansible to a target collection.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# PYTHON_ARGCOMPLETE_OK
# Copyright: (c) 2020, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
"""
Script that can be used to copy issues and PRs from the Ansible GitHub repo to it's target collection repo. Current
limitations are;