Skip to content

Instantly share code, notes, and snippets.

# Define callback
$CallbackScript = {
Param (
[Int32]$Code,
[IntPtr]$wParam,
[IntPtr]$lParam
)
$MsgType = $wParam.ToInt32()
function Get-Keystrokes {
[CmdletBinding()]
Param (
[Parameter(Position = 0)]
[ValidateScript({Test-Path (Resolve-Path (Split-Path -Parent -Path $_)) -PathType Container})]
[String]$LogPath = "$($env:TEMP)\key.log",
[Parameter(Position = 1)]
[Double]$Timeout,
@secabstraction
secabstraction / elasticsearch.yml
Created February 8, 2016 19:46 — forked from reyjrar/elasticsearch.yml
ElasticSearch config for a write-heavy cluster
##################################################################
# /etc/elasticsearch/elasticsearch.yml
#
# Base configuration for a write heavy cluster
#
# Cluster / Node Basics
cluster.name: logng
# Node can have abritrary attributes we can use for routing
@secabstraction
secabstraction / logstash-template.json
Created February 8, 2016 19:47 — forked from reyjrar/logstash-template.json
Template for logstash indexes
{
"template": "logstash-*",
"settings" : {
"index.number_of_shards" : 3,
"index.number_of_replicas" : 1,
"index.query.default_field" : "@message",
"index.routing.allocation.total_shards_per_node" : 2,
"index.auto_expand_replicas": false
},
"mappings": {
function Get-CimEvents {
[CmdLetBinding(DefaultParameterSetName = 'Filter')]
param (
[Parameter(Mandatory = $true)]
[Alias('Session')]
[Microsoft.Management.Infrastructure.CimSession[]]
$CimSession,
[Parameter(ParameterSetName = 'Filter')]
[ValidateNotNullOrEmpty()]
# Create a simple client via Elastic's Uri
$Client = New-ElasticClient -Node http://myelastic:9200
# Test connection
$Client.CatHealth()
# Stash
$Client.BulkAsync($AllTheThings)
# Create a connection pool
$Pool = New-ConnectionPool -Nodes @('http://test1:9200','http://test2:9200') -Sniffing
# Create a connection configuration from the pool
$Config = New-ConnectionConfiguration -Pool $Pool
# Tweak the configuration
$Config.SetBasicAuthentication('username','password')
$Config.SetProxy('http://myproxy:8080','username','password')
begin { $JsonStrings = [Collections.Generic.List[String]]::new() }
process {
foreach ($Object in $InputObject) {
$IndexProperties = @{
index = @{
_index = $Index
_type = $Type
_id = $Id
# First lets collect some objects
$Logons = Get-CimInstance -ClassName Win32_NtLogEvent -Filter "LogFile='Security' AND EventCode='4624'"
# Now for the export
$Logons | Export-Elastic -Node http://myelastic:9200
$Parameters = @{
CimSession = $CimSession
ClassName = 'Win32_NTLogEvent'
Filter = $Filter
ErrorAction = 'Continue'
ErrorVariable = 'Errors'
}
Get-CimInstance @Parameters | foreach {