Skip to content

Instantly share code, notes, and snippets.

@elvarb
elvarb / ConvertFrom-Xml.ps1
Created June 24, 2019 13:45
Powershell to convert XML to JSON
# From https://stackoverflow.com/questions/42636510/convert-multiple-xmls-to-json-list
# Use
# [xml]$var = Get-Content file.xml
# Convert to JSON with
# $var | ConvertFrom-XML | ConvertTo-JSON -Depth 3
# Helper function that converts a *simple* XML document to a nested hashtable
# with ordered keys.
function ConvertFrom-Xml {
param([parameter(Mandatory, ValueFromPipeline)] [System.Xml.XmlNode] $node)
@elvarb
elvarb / genlog.ps1
Last active June 11, 2019 14:28
Generate constant stream of data to a log file, for testing log shipping and log handling. Each line includes a ISO timestamp and a random number of characters.
# Modify start-sleep to change how frequent log lines should be generated
# Modify out-file to change target log file
#
# Example output:
# 2019-11-06 14:27:16 CHQvrjBqXbwFfUOgRc
# 2019-11-06 14:27:16 RxEOpUqrjaIeLMzoiDyAHvg
# 2019-11-06 14:27:17 DALVZYy
# 2019-11-06 14:27:17 mjlSvTENJ
# 2019-11-06 14:27:17 mHBtcDTuOZWqyKEFSdVzglMAivRjQpsw
# 2019-11-06 14:27:17 QPMpZrhtsGcxyqwuBzHfmvaAkNgCe

Keybase proof

I hereby claim:

  • I am elvarb on github.
  • I am elvarb (https://keybase.io/elvarb) on keybase.
  • I have a public key ASDZzDklDOkPBni0NHij3M0aeVH49H1yZaym2TafaNWHSAo

To claim this, I am signing this object:

@elvarb
elvarb / golistdeps.ps1
Created November 7, 2017 10:37
Powershell script to list all dependencies in a Go project, if a dependency is found on Github the Github API is queried for the license
$username = "" # Github Username
$key = "" # Github API key
$goapp = "" # Go Project Name
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$key)))
$deps = ((go list -f '{{ .Deps }}' $goapp).Trim('[',']')).split(' ')
$deps | %{
write-host $_
@elvarb
elvarb / golistdeps.ps1
Created November 7, 2017 09:53
Powershell one liner that lists all dependencies in a Go application
$goapp = 'myapp'
((go list -f '{{ .Deps }}' $goapp).Trim('[',']')).Replace(' '," `n")
@elvarb
elvarb / gist:d7393e041f4ce7e7bff4
Created May 13, 2015 10:53
Logstash on Windows
Download the following
* Logstash https://www.elastic.co/downloads/logstash
* Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
* NSSM https://nssm.cc/
Create this folder structure
\Logstash
\Logstash\config
\Logstash\java
@elvarb
elvarb / Report-WSUSNodesUpdateReport.ps1
Created May 20, 2012 21:22
Powershell: WSUS Nodes Update Report
import-module poshwsus
connect-wsusserver WSUS.domain.com
$nodes = Get-WSUSUpdateSummaryPerClient -ComputerScope (New-WSUSComputerScope) -UpdateScope (New-WSUSUpdateScope) | sort-object NeededCount -descending | select-object Computer,LastUpdated,NeededCount,InstalledPendingRebootCount,InstalledCount,FailedCount
$emailto = "email@domain.com"
$emailfrom = "wsus@domain.com"
$message = $null
@elvarb
elvarb / SendEmail.ps1
Created May 20, 2012 21:08
Powershell: Send Email
param(
[string]$From = "powershell@domain.com",
$To = "email@domain.com",
[string]$Priority = "High",
[string]$SMTPServer = "smtp.domain.com",
$Encoding = [System.Text.Encoding]::UTF8,
[string]$Subject = $(throw "Argument and value for '-Subject' is required."),
[string]$Message = $(throw "Argument and value for '-Message' is required."),
[string]$Attachments = "No"
)
@elvarb
elvarb / pingcheck.ps1
Created May 8, 2012 10:19
Powershell: Pingcheck
$servers = "microsoft.com","google.com"
$servers | %{
if (test-Connection -ComputerName $_ -Count 2 -Quiet ) {
echo "$_ is online!"
} else {
$emailFrom = "PingCheck@yourdomain.com"
$emailTo = "you@yourdomain.com"
$subject = "$_ Is down!"
$body = "Holy shit, you should do something about this."