Skip to content

Instantly share code, notes, and snippets.


Chris Allen Packet-Lost

View GitHub Profile
Packet-Lost / Show-ThisPSOddity.ps1
Last active Jan 18, 2020
A function that displays errors during validated parameter type changes
View Show-ThisPSOddity.ps1
function Show-ThisPsOddity {
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][ValidateSet("foo", "bar", "baz", "match")][String]$UserInput,
[ValidateRange(1,2)][int]$Variant = 1
switch($variant) {
1 { if($UserInput -eq "match"){ $UserInput = @("foo", "bar", "baz") } }
View EnsurePlex.ps1
$plexstatus = (systemctl | grep plex) | Out-String
if($plexstatus.length -eq 0 ){ $startplex = $true }
try{ $plexfind = $plexstatus.trim().Split('loaded ')[1].Split(' ')[1]}
catch { $plexfind = $null }
if ($plexfind -ne 'running') { $startplex = $true }
systemctl start plexmediaserver.service
Add-Content /srv/logs/plexstart.log "$(Get-Date) Started plex."
} else { Write-Output 'Plex check completed, no need to start plex. Exiting.' }
Packet-Lost / Set-S3BucketEncryption.ps1
Created Oct 16, 2018
Set default server side encryption on an s3 bucket with powershell
View Set-S3BucketEncryption.ps1
Set-S3BucketEncryption -BucketName BucketNameGoesHere -ServerSideEncryptionConfiguration_ServerSideEncryptionRule @{ServerSideEncryptionByDefault=@{ServerSideEncryptionAlgorithm="AES256"}}
Packet-Lost /
Last active Sep 28, 2018
Troposphere / boto3 dynamic vpc cloudformation template creation
import boto3
import time
import os
from troposphere import Base64, FindInMap, GetAtt, Join, Output
from troposphere import Parameter, Ref, Tags, Template
from troposphere.ec2 import PortRange, NetworkAcl, Route, \
SubnetRouteTableAssociation, Subnet, RouteTable, \
VPCGatewayAttachment, VPC, NetworkInterfaceProperty, NetworkAclEntry, \
SubnetNetworkAclAssociation, EIP, Instance, InternetGateway
View us-east-1-dynamic-vpc-20170904-102113.template
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"IGWAttachment": {
"Properties": {
"InternetGatewayId": {
"Ref": "InternetGateway"
"VpcId": {
"Ref": "VPC"
Packet-Lost /
Created Apr 12, 2017
Python solution to google's foobar the cake is not a lie
from __future__ import division
from __future__ import print_function
def answer(s):
if not bool(s):
return 0
result = 0
howlong = len(s)
i = howlong
while i > 0:
Packet-Lost / Test-ReadRouting.ps1
Created Aug 26, 2017
Test AlwaysOn Application Read Intent Routing with PowerShell
View Test-ReadRouting.ps1
##replace variables as needed##
$Server = ''
$Database = 'DatabaseInsideAvailabilityGroup'
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "Server=$($Server);Database=$($Database);Integrated Security=True;MultiSubnetFailover=True"
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection
Packet-Lost / CreateSecurityGroups.ps1
Created Apr 9, 2017
Create AWS security groups and configure ingress rules via lookups with PowerShell
View CreateSecurityGroups.ps1
#Requires Modules AWSPowerShell
$myonlyvpc = (Get-EC2Vpc).VpcId
$elbsg = New-EC2SecurityGroup -VpcId $myonlyvpc -GroupName "My ELB Security Group" -Description "Created by script on $((Get-Date).tostring('u'))"
New-EC2Tag -ResourceId $elbsg -Tag @{Key="Name"; Value="My ELB Security Group"}
$httpallowall = New-Object Amazon.EC2.Model.IpPermission -Property @{IpProtocol=”tcp”;FromPort=80;ToPort=80;IpRanges=""}
$httpsallowall = New-Object Amazon.EC2.Model.IpPermission -Property @{IpProtocol=”tcp”;FromPort=443;ToPort=443;IpRanges=""}
You can’t perform that action at this time.