Skip to content

Instantly share code, notes, and snippets.

$Host.UI.RawUI.WindowTitle = "-=Windows Update=-"
$Script = $MyInvocation.MyCommand.Definition
Write-Host -NoNewline "Checking for Updates..."
$UpdateSession = New-Object -Com Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and Type='Software'")
For ($X = 0; $X -lt $SearchResult.Updates.Count; $X++) {
$Update = $SearchResult.Updates.Item($X)
param ([string]$SrcDBInstance, [string]$DestDBInstance, [string]$DBName)
#Functions
function Exec-Query ([string]$DBServer,[string]$DBName,[string]$Query) {
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$DBServer;Database=$DBName;Integrated Security=True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandTimeout = 0
$SqlCmd.CommandText = $Query
$SqlCmd.Connection = $SqlConnection
Import-Module -Name D:\Temp\ACME-posh\ACMEPowerShell.psd1
$domain = "mydomain.com"
$certificiatePassword = "abcd1234"
$email = "letsencrypt@mydomain.com"
$vault = "D:\Vault\{0}\{1}" -f $domain, [guid]::NewGuid()
mkdir $vault
cd $vault
Initialize-ACMEVault -BaseURI https://acme-v01.api.letsencrypt.org/
New-ACMERegistration -Contacts mailto:$email
@onyxhat
onyxhat / sh_env_var_opts.sh
Created May 21, 2016 14:20 — forked from KylePDavis/sh_env_var_opts.sh
Simple bash shell script templates. There are two versions: 1) simple env var based options, and 2) with added command line argument parsing and error handling.
#!/bin/bash -e
# A SHORT DESCRIPTION OF YOUR SCRIPT GOES HERE
# USAGE:
# DESCRIPTION OF ENV VARS HERE
###############################################################################
set -e # exit on command errors (so you MUST handle exit codes properly!)
set -o pipefail # capture fail exit codes in piped commands
#set -x # execution tracing debug messages
# Get command info
#! /bin/bash
set -e
#Re-run the script if not using sudo/root
detect_current_uid() {
echo $(id -u)
}
rerun_script_as_root() {
if [ $(detect_current_uid) -ne "0" ]; then
@onyxhat
onyxhat / win32.go
Last active June 24, 2016 02:55 — forked from nathan-osman/win32.go
Simple Windows GUI application written in Go
package main
import (
"log"
"syscall"
"unsafe"
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
@onyxhat
onyxhat / Parse-ChocoParams.ps1
Last active July 15, 2016 15:24
Stub for parsing Chocolatey --params string into variables in the chocolateyinstall.ps1/chocolateyuninstall.ps1
#$packageParameters = $env:chocolateyPackageParameters
$packageParameters = "var1 = val1;var2=`"val2 with spaces -`""
$match_pattern = "(?<key>(\w+))\s*=\s*(?<value>([`"'])?([\w- _\\:\.]+)([`"'])?)"
# Now parse the packageParameters using good old regular expression
if ($packageParameters -match $match_pattern ) {
$results = $packageParameters | Select-String $match_pattern -AllMatches
$results.matches | % {
Set-Variable -Name $_.Groups['key'].Value.Trim() -Value $_.Groups['value'].Value.Trim()
}
@onyxhat
onyxhat / main.go
Created January 8, 2018 01:39 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@onyxhat
onyxhat / remove_floppy.sh
Last active June 15, 2018 03:05
Ubuntu fd0 Errors on boot in Hyper-V
#! /bin/bash
set -e
#Re-run the script if not using sudo/root
detect_current_uid() {
echo $(id -u)
}
rerun_script_as_root() {
if [ $(detect_current_uid) -ne "0" ]; then
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Is a useful one-liner which will give you the full directory name of the script no matter where it is being called from

These will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you want to also resolve any links to the script itself, you need a multi-line solution:

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink