Skip to content

Instantly share code, notes, and snippets.

@slimflem
slimflem / Example.ps1
Created May 2, 2016 00:50 — forked from nblumhardt/Example.ps1
Seq from Powershell POC
Import-Module Seq
# Specify the Seq server URL; an -apiKey can also be provided.
# Any properties set here will be attached to all events.
$seq = Open-Seq "http://my-seq" -properties @{ Machine = $env:ComputerName }
# Simple information method
Send-SeqEvent $seq "Hello from PowerShell"
@slimflem
slimflem / batch-start-windows-services.ps1
Last active December 5, 2016 10:59
Batch Start Windows Services with common service name prefix (OctopusDeploy)
<#
This script will start any non-disabled SystemX service on the machine on which it is run.
This script, as written, executes as part of an OctopusDeploy project.
#>
# Receive OctopusDeploy parameter that indicates the SystemX Service name prefix value.
# Capture supplied OctopusDeploy variable in a local variable.
$prefixValue = $OctopusParameters['SystemXServiceNamePrefix']
Write-Output "SystemX Service prefix value is: $prefixValue"
@slimflem
slimflem / mongodb_logrotate.cron
Created April 1, 2016 19:28
Rotate and compress mongodb logs
#!/bin/bash
# To be used as a cron job weekly (or other) placed under /etc/cron.weekly
# Will use mongodb's logrotate function, but then will compress and keep at most 12 weeks worth of rotate logs.
killall -SIGUSR1 `cat /var/run/mongodb/mongod.pid`
gzip /var/log/mongodb/*20[0-9][0-9]-*-[0-9][0-9]
logs_total=`ls -tx1 /var/log/mongodb/ | egrep "20[0-9][0-9]-.*\.gz" | wc -l`
if [ "$logs_total" -gt 12 ]; then
logs_difference=`expr $logs_total - 12`
logs_to_remove=`ls -tx1 /var/log/mongodb/ | egrep "20[0-9][0-9]-.*\.gz" | tail -n $logs_difference`
for log_file in $logs_to_remove; do
@slimflem
slimflem / gist:3b27218644e5c745e6e5
Created February 19, 2016 15:18 — forked from stevenkuhn/gist:5062660
This PowerShell script generates release notes for Octopus Deploy that contain the GitHub commits and JIRA issues from the current build to the latest production release. It will also create the Octopus release based on the TeamCity build number.
#
# Assumptions
#
# 1. If you have a Octopus release deployed, say 1.0.0.73, there is a git
# tag set for that commit in GitHub that is "v1.0.0.73".
#
# 2. You have TeamCity label each successful build in GitHub with the format
# "v{build number}. Sidenote: it appears that TeamCity only labels the
# default branch, but not feature branches.
#
db.people.find().forEach( function(x){db.user.insert(x)} );
class Program
{
static int bats = 0;
static int frogs = 0;
static void Main(string[] args)
{
using (var store = new EmbeddableDocumentStore())
{
store.Initialize();
@slimflem
slimflem / gist:6407436
Created September 1, 2013 21:29
encode data to byte[]. in this case, IDataStructure is a marker interface only that is inherited by structs.
internal static byte[] EncodeToBytes(this IDataStructure data)
{
// get the unmanaged size of the data in bytes being marshalled.
var size = Marshal.SizeOf(data);
// allocate unmanaged memory of size bytes.
var ptr = Marshal.AllocHGlobal(size);
// marshall the data from managed to unmanaged memory.
// passing true as the last parameter allows all unmanaged
@slimflem
slimflem / SetLanmanDependencyForWinSvc.bat
Last active December 22, 2015 02:59
sc.exe to set a dependency on LanmanWorkstation for a Windows Service. This is useful to ensure a Windows Service does not start until one of the very last services to start on the machine.
sc.exe config MyCustomService depend= LanmanWorkstation
@slimflem
slimflem / SetUserCredsForWinSvc.bat
Created September 1, 2013 21:17
sc.exe to set user credentials on a Windows Service
sc.exe config MyCustomService obj= user@company.com password= "password"
@slimflem
slimflem / DeleteWindowsService.ps1
Created September 1, 2013 21:14
Checks for the existence of and deletes a Windows Service.
if (Get-Service "MyCustomService" -ErrorAction SilentlyContinue) {
sc.exe delete MyCustomService | Write-Host
}