Skip to content

Instantly share code, notes, and snippets.

View Sam-Martin's full-sized avatar

Sam Martin Sam-Martin

View GitHub Profile
@Sam-Martin
Sam-Martin / Invoke-KMSEncrypt-Example.ps1
Last active June 16, 2020 17:53
PowerShell Example for using Invoke-KMSEncrypt and Invoke-KMSDecrypt
# Stolen from http://ctrlf5.net/?p=263 and http://www.dailycoding.com/posts/convert_image_to_base64_string_and_base64_string_to_image.aspx
function ConvertFrom-StringToMemoryStream{
param(
[parameter(Mandatory)]
[string]$InputString
)
$stream = New-Object System.IO.MemoryStream;
$writer = New-Object System.IO.StreamWriter($stream);
$writer.Write($InputString);
@Sam-Martin
Sam-Martin / aws-userdata-new-user-psremoting-enabled.ps1
Created March 8, 2016 14:21
Create standard user and enable PS Remoting in AWS UserData
<powershell>
Enable-PSRemoting -force
Set-Item WSMan:\localhost\MaxTimeoutms 1800000
Set-Item WSMan:\localhost\Service\AllowRemoteAccess $true
Set-Item WSMan:\localhost\Service\Auth\Basic $true
Set-item WSMan:\localhost\Service\AllowUnencrypted $true
$computername = $env:computername # place computername here for remote access
$username = 'AdminAccount1'
$password = 'topSecret@99'
@Sam-Martin
Sam-Martin / QueueTrigger.ps1
Last active April 16, 2016 15:17
An example of how to create a PowerShell based HTTP request based Azure Function
# Get input and output params (as named in our function.json)
$result = $Env:res
$requestPath = $env:req
$executionPath = Split-Path -parent $PSCommandPath
$tempPath = Split-Path -parent $env:req
# Read the input from file and parse it to an object
[Console]::WriteLine("Reading input from $env:req")
$requestObj = get-content $requestPath | out-string | convertfrom-json
@Sam-Martin
Sam-Martin / RightGIF Integration for HipChat using AWS Lambda.py
Created April 26, 2016 20:28
RightGIF Integration for HipChat using AWS Lambda
import urllib
import urllib2
import json
def lambda_handler(event, context):
url = 'https://rightgif.com/search/web'
@Sam-Martin
Sam-Martin / Get-ServiceWPF.ps1
Last active April 28, 2016 08:11
Get-Service WPF PowerShell Get-PSUGUK 2016.04.27
Add-Type -AssemblyName PresentationFramework
[xml]$XAMLWindow = '
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="Auto"
SizeToContent="WidthAndHeight"
Title="Get-Service">
<ScrollViewer Padding="20">
@Sam-Martin
Sam-Martin / Pingdom2HipChat.ps1
Last active May 17, 2016 10:36
Pingdom2HipChat
# Get input and output params (as named in our function.json)
$result = $Env:res
$requestPath = $env:req
$executionPath = Split-Path -parent $PSCommandPath
$tempPath = Split-Path -parent $env:req
# Read the input from file and parse it to an object
[Console]::WriteLine("Reading input from $env:req")
$requestObj = Get-Content $requestPath | Out-String | ConvertFrom-Json
@Sam-Martin
Sam-Martin / Update-PingdomChecksIntegrationID.ps1
Created May 18, 2016 09:38
Update all your pingdom checks to use a single ID
$VerbosePreference = "Continue"
if(!$cred){
$cred = Get-Credential
}
$IntegrationID = 707
if($(Read-Host "Warning, this will replace all checks' integrations with ONLY integration ID $integrationID, do you wish to continue? y/n") -ne 'y'){
return;
}
$params = @{
uri = "https://api.pingdom.com/api/2.0/checks"
@Sam-Martin
Sam-Martin / Get-StationsInLondon
Last active May 21, 2016 20:02
A quick PowerShell way to get the lats and longs of all stations in the Greater London area (and a bit more besides)
$hashResult = @{}
if(!$TubeStationsRAW){
$TubeStationsRAW =@()
$page = 0
while(1){
$page += 1;
Write-Verbose "Looking at page $page"
$result = $(invoke-webrequest "https://api.tfl.gov.uk/StopPoint/Mode/tube,overground,national-rail?page=$page").content | ConvertFrom-Json
if(!$result){
return
@Sam-Martin
Sam-Martin / PagerDutyToSplunk.py
Last active May 27, 2016 16:25
PagerDutyToSplunk.py
import os
import json
import urllib
import urllib2
from datetime import datetime
from datetime import timedelta
import json
@Sam-Martin
Sam-Martin / PagerdutyDashboard.xml
Created May 30, 2016 14:28
PagerDuty Splunk Dashboard
<dashboard>
<label>Operational Dashboard</label>
<row>
<panel>
<chart>
<title>Total callouts last 30 days</title>
<search>
<query>index="pagerduty" AND ("channel.notification.type" = *_push_notification OR "channel.notification.type" = SMS OR "channel.notification.type" = Phone) |
timechart count by "user.summary"</query>
<earliest>-30d@d</earliest>