Skip to content

Instantly share code, notes, and snippets.

View espoelstra's full-sized avatar

Ethan Spoelstra espoelstra

View GitHub Profile
@espoelstra
espoelstra / .bats-mock-SO.md
Last active September 30, 2018 02:19
Bats-mock which to use?
@espoelstra
espoelstra / .freedos-pxe-boot.md
Created September 26, 2018 21:52
Creating a FreeDOS image for PXE boot

FreeDOS easy to update USB or PXE boot (Legacy or EFI)

I've been wanting to do this for quite a while, ever since I had to make up dozens of USB drives with a system image for deployment to migrate from Windows XP to Windows 7 for a large enterprise. Any tweaks to the image required re-writing all the drives, and the quickest way to burn up a cheap drive is repeated reads and writes. Then I learned partway through the rollout from the support staff performing the hands-on reimaging that on some systems the boot took forever, and while investigating I discovered that there was a BIOS update that remedied the issue and the system boot dropped from 10-15 minutes to a minute or two. After that I added updating the BIOS to our reimage procedure checklist, but again I was making multiple copies of the USB so that each tech could have one to do the fairly quick BIOS update before switching over to the other USB for imaging the system. Luckily at the time I had opted for the USB "full" image of FreeDOS which had sp

@espoelstra
espoelstra / !powershell-hijinks.md
Created September 24, 2018 02:08
PowerShell hijinks

If wanting to run a .ps1 with a double click it IS possible to edit the registry to allow this, the issue is that scripts that aren't elevated may fail, and it bypasses some of the ExecutionPolicy restrictions or hardcodes the same policy for all of them.

This Q&A has a number of options for making it work, but the best practice scenario I'm going with is creating a .bat file to call a .ps1 file, and then putting a shortcut to the .bat file on the Public Desktop so that the shortcut can be set to run as Administrator and prompt for the password if UAC is configured that way.

https://stackoverflow.com/questions/10137146/is-there-any-way-to-make-powershell-script-work-by-double-clicking-ps1-file

For reference the "Run with PowerShell" in the right click menu uses this as the "Command" registry key, "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"

If a user has changed the association

@espoelstra
espoelstra / !BashMadness.md
Created August 31, 2018 13:24
As a Bash scripter, I want to be able to handle required positional parameters without updating my $# compare to see if enough were supplied constantly

Bash Madness

This was conceived out of a desire to avoid if [ -z $1 ]; then echo "SomeVar required"; exit 1; fi for all the positionals since the number I want to handle might change. Eventually it may handle shift and named or - or -- delimited arguments, but we are starting of simple slow.

@espoelstra
espoelstra / .a.md
Created August 7, 2018 20:37
Windows AD RFC 2307 Linux Unix LDAP attributes

Keybase proof

I hereby claim:

  • I am espoelstra on github.
  • I am ewspoelstra (https://keybase.io/ewspoelstra) on keybase.
  • I have a public key ASA4Wj5n6SKF6igKIU17oqoo1MCo5aCHClgnczS_YobHKgo

To claim this, I am signing this object:

@espoelstra
espoelstra / Test-RebootRequired.ps1
Last active April 4, 2017 16:22 — forked from altrive/Test-RebootRequired.ps1
Check pending reboot on local computer (2008R2 and 2012R2 compatible ErrorAction)
#Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
function Test-RebootRequired
{
$result = @{
CBSRebootPending =$false
WindowsUpdateRebootRequired = $false
FileRenamePending = $false
SCCMRebootPending = $false
}
@espoelstra
espoelstra / gist:66d2c41f829892fe0655270574d9d314
Created January 6, 2017 23:09 — forked from ig0774/gist:1068598
Manage Windows Advanced Firewall with PowerShell
Set-StrictMode -Version Latest
# Constants
if (!(Test-Path variable:\NET_FW_DISABLED)) { Set-Variable NET_FW_DISABLED $False }
if (!(Test-Path variable:\NET_FW_ENABLED)) { Set-Variable NET_FW_ENABLED $True }
if (!(Test-Path variable:\NET_FW_IP_PROTOCOL_TCP)) { Set-Variable NET_FW_IP_PROTOCOL_TCP 6 }
if (!(Test-Path variable:\NET_FW_IP_PROTOCOL_UDP)) { Set-Variable NET_FW_IP_PROTOCOL_UDP 17 }
if (!(Test-Path variable:\NET_FW_PROFILE_DOMAIN)) { Set-Variable NET_FW_PROFILE_DOMAIN 0x1 }
if (!(Test-Path variable:\NET_FW_PROFILE_PRIVATE)) { Set-Variable NET_FW_PROFILE_PRIVATE 0x2 }
if (!(Test-Path variable:\NET_FW_PROFILE_PUBLIC)) { Set-Variable NET_FW_PROFILE_PUBLIC 0x2 }
@espoelstra
espoelstra / Install-OctopusServer.ps1
Created January 5, 2017 19:05 — forked from davidroberts63/Install-OctopusServer.ps1
Automate Octopus Deploy Server Install and Configuration
$commandArgs = "/i Octopus-Server.msi /quiet INSTALLLOCATION=C:\OctopusServer /lv Octopus-Server-Install-Log.txt"
Start-Process "msiexec" $commandArgs -Wait -Verb RunAs
@espoelstra
espoelstra / gist:e63e6ef9f4fc2c1a85ddb3066a4cd33e
Created December 30, 2016 23:35 — forked from DamianMac/gist:a944c0fcab6db531e7a5
Executing a Script Task via the Octopus API
var server = "http://yourserveraddress:8065/"; //Your server and IP address
var apiKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXX"; // Get this from your 'profile' page in the Octopus web portal
var endpoint = new OctopusServerEndpoint(server, apiKey);
var repository = new OctopusRepository(endpoint);
var task = new Octopus.Client.Model.TaskResource();
task.Name = "AdHocScript";
task.Description = "Script invoked via API";