Skip to content

Instantly share code, notes, and snippets.

View halr9000's full-sized avatar
👋
🤙

Hal Rottenberg halr9000

👋
🤙
View GitHub Profile
function ConvertTo-SplunkString
{
[cmdletbinding()]
param(
[Parameter(ValueFromPipeline=$true)]
[Object]$InputObject,
[Parameter()]
[System.Collections.Hashtable]$Properties
)
@halr9000
halr9000 / Add-SplunkVmwarePermission.ps1
Created July 2, 2012 15:28
Use this script to assign Splunk for VMware vCenter permisisons to a specified Active Directory account
<#
.SYNOPSIS
Use this script to assign Splunk for VMware vCenter permisisons to a specified Active Directory account
.DESCRIPTION
Use this script as a companion to performing the installation steps for Splunk for VMware. It is
necessary to first create a service account in Active Directory to which the required permissions
are then assigned. This script will assign the permissions to all visible datacenters. To assign
permissions across multiple vCenter servers, login to them first by using the Connect-ViServer
cmdlet with the AllLinked parameter (assuming that you are using the Linked mode feature of vCenter
Server.)
Param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
$Recipient
)
Begin {
# Edit these as needed
$MailParam = @{
From = "[email protected]"
Subject = "Your vExpert Eval Keys"
@halr9000
halr9000 / Send-Pushover.ps1
Created August 8, 2012 19:45
Sample to send message via Pushover from Windows PowerShell
# Using any version of PowerShell
$parameters = New-Object System.Collections.Specialized.NameValueCollection
$parameters.Add("token", "APP_TOKEN")
$parameters.Add("user", "USER_KEY")
$parameters.Add("message", "hello world")
$client = New-Object System.Net.WebClient
$client.UploadValues("https://api.pushover.net/1/messages.json", $parameters)
# Using PowerShell v3 only with new Invoke-RestMethod cmdlet
$uri = 'https://api.pushover.net/1/messages.json'
@halr9000
halr9000 / Get-Gist.ps1
Created August 9, 2012 15:39
Read public gists using PowerShell (quick example)
# this gets even easier in v3 with the Invoke-RestMethod cmdlet
$uri = 'https://api.github.com/users/halr9000/gists'
Invoke-RestMethod -Uri $uri
@halr9000
halr9000 / splunk2.psm1
Last active December 17, 2015 16:29
Simple PowerShell module for Splunk with a connect and disconnect function. Module is based on the Splunk C# SDK which can be downloaded from http://dev.splunk.com/view/SP-CAAAEPK. To use, place this script and the SplunkSDK.dll from the SDK archive into a folder called "Splunk2" in your PSModulePath. PowerShell version 3 is required.
#Requires -Version 3
# Import Splunk C# SDK types into module scope
Add-Type -Path "$PSScriptRoot\SplunkSDK.dll"
<#
.Synopsis
Connects to a Splunk server
.DESCRIPTION
This function connects to a Splunk server via the REST API and creates a service object called $SPLUNK_SERVICE.
@halr9000
halr9000 / Export-SplunkSearch.ps1
Created September 18, 2013 04:27
Splunk export search job using PowerShell
# Conversion of http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#search.2Fjobs.2Fexport
# example using curl, to PowerShell with Invoke-RestMethod cmdlet
#
# $ curl -k -u admin:changeme https://localhost:8089/services/search/jobs/export
# --data-urlencode search="search index=_internal | stats count by sourcetype"
# -d output_mode=json -d earliest="rt-5m" -d latest="rt"
$cred = Get-Credential
# This will allow for self-signed SSL certs to work
import sys, time, os, csv
import httplib, urllib, hashlib, base64, hmac, urlparse, md5
import xml.dom.minidom, xml.sax.saxutils
import logging
import tarfile, gzip
ENDPOINT_HOST_PORT = "s3.amazonaws.com"
# set up logging suitable for splunkd consumption
logging.root
@halr9000
halr9000 / CiscoUcs.py
Created June 19, 2014 13:46
Splunk Python scripts to collect data from Cisco UCS
import warnings
__author__ = 'JBennett'
# A class wrapper for calls to Cisco UCS Managers
#! /Library/Frameworks/Python.framework/Versions/2.7/bin/python
########################################
## Library functions
########################################
from datetime import datetime
@halr9000
halr9000 / splunkutils.ps1
Created June 27, 2014 14:54
PowerShell function to start Splunk
Function Start-Splunk {
try {
Get-Service splunk* | Start-Service -ErrorAction Stop
}
catch [Microsoft.PowerShell.Commands.ServiceCommandException] {
Write-Verbose "Command must be run in an elevated session, invoking new session."
Start-Process -Verb Runas -FilePath powershell.exe { Get-Service splunk* | Start-Service -Verbose -ErrorAction Stop; Start-Sleep 5 }
}
}