Skip to content

Instantly share code, notes, and snippets.

View JPRuskin's full-sized avatar

James Ruskin JPRuskin

View GitHub Profile
@JPRuskin
JPRuskin / rdpupyet.ps1
Last active August 15, 2022 11:58
RDP Up Yet
<#
.Synopsis
Checks for and connects to RDP on a given server.
.Description
This script tests for an open port 3389 (standard Windows RDP), and if it finds it, passes the IP to mstsc.exe. Otherwise it retries indefinitely. Ctrl+C will halt the script.
.Parameter ip
IP or FQDN of a Windows machine to test. Only takes one argument.
.Parameter wait
Will assume that the machine is still up, wait until it stops responding (even once), and then try to connect.
Good for machines that are about to reboot.
function Get-Deck {
param([int]$decks=1)
$return = Invoke-WebRequest -Uri "http://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=$decks"
if ($return.StatusCode -eq 200) {return $return.Content | ConvertFrom-Json}
else {break $return.StatusCode}
}
function Get-Cards {
param(
[Parameter(ValueFromPipelineByPropertyName,Mandatory)]
@JPRuskin
JPRuskin / Get-StarCitizen.ps1
Last active December 4, 2015 01:26
Gets all of the files from the public or test StarCitizen manifests and downloads them to $directory (prompts if not imported).
function Get-StarCitizenManifest {
[CmdletBinding(SupportsShouldProcess)]
param()
$return = Invoke-WebRequest -Uri 'http://manifest.robertsspaceindustries.com/Launcher/_LauncherInfo' -OutFile $env:temp/launcherInfo
Get-Content -Path $env:temp/launcherInfo | ConvertFrom-StringData
}
function Get-StarCitizenFiles {
[CmdletBinding(SupportsShouldProcess)]
param(
// ==UserScript==
// @name BetterHangar
// @namespace http:\\justpowerdown.com
// @version 0.3
// @updateURL https://gist.githubusercontent.com/JPRuskin/4c052f42efb3acd691ad/raw/betterhangar.js
// @downloadURL https://gist.githubusercontent.com/JPRuskin/4c052f42efb3acd691ad/raw/betterhangar.js
// @description Adds some additional functionality to the Pledges (Hangar) page on RSI
// @author @JPRuskin
// @match https://robertsspaceindustries.com/account/pledges*
// @grant none
@JPRuskin
JPRuskin / Update-SysInternals.ps1
Last active April 16, 2017 00:59
Updates all SysInternals tools contained within $localDirectory from live.sysinternals.com.
function Get-SysInternalsTools {
[CmdletBinding(DefaultParameterSetName='Update')]
param(
[Parameter(Mandatory)]
$localDirectory,
[Parameter(ParameterSetName='Download')]
[Switch]$DownloadAll
)
begin {
$localTools = Get-ChildItem $localDirectory -Filter *.exe
@JPRuskin
JPRuskin / DiskReport.sh
Last active September 2, 2016 14:28
E-mails a warning to the e-mail address when disk-usage on the main partition is over 90% ($threshold). Overwrites a log with the last runtime and usage stat. Requires SSMTP
#! /bin/bash
CURRENT=$(df / | grep / | awk '{ print $5 }' | sed 's/%//g')
THRESHOLD=90
LOGFILE=~/Scripts/DiskReport.log
echo "Last Run: $(date "+%d%m%Y %T") : $CURRENT% Used." > $LOGFILE
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
ssmtp -s 'Disk Space Alert' [email protected] << EOF
Root partition remaining free space is critically low. Used: $CURRENT%
<#
.Synopsis
Begins an Azure DirSync.
.Description
Contains a function that will connect to a server (defaulting to ADFS01), load the Azure DirSync profile, and kick off a sync.
Prompts for creds regardless of account, but can be given credentials to use.
.Parameter server
The server to connect to. Defaults to ADFS01.
.Parameter Credential
Credentials to try connecting to the server with.
@JPRuskin
JPRuskin / qif_datefix.py
Created June 20, 2016 14:06
Converts dates in a QIF formatted file from %b to %m.
import sys, re
from datetime import datetime
if sys.argv[1].lower().endswith(".qif"):
redate = re.compile("D\d{2}\/\D{3}\/\d{4}")
with open(sys.argv[1], "r") as infile:
print("Now reading "+infile.name+"...")
with open(sys.argv[1][:-4]+"_converted.qif", 'w') as outfile:
@JPRuskin
JPRuskin / export-hashtable.ps1
Last active September 28, 2016 13:49
Converts [PSObjects] into a format suitable for storing in a file, so you can dot-source hashtables.
function Export-HashTable {
param(
[Parameter(Mandatory, ValueFromPipeline)]
[Alias('InputObject')]
[PSObject]$HashTable,
[String]$Path,
[String]$Name
)
process {
$divWidth = ($HashTable.Keys.Length | Measure-Object -Maximum).Maximum + 8
@JPRuskin
JPRuskin / get-scriptfunctions.ps1
Last active June 9, 2019 10:47
Function to list all functions within a script or scriptblock. Can then be piped to iex to effectively dot-source just the functions from a given file/block, or output to a file to concat a module of functions.
function Get-ScriptFunctions {
<#
.SYNOPSIS
Lists all functions within a script or scriptblock.
.DESCRIPTION
Uses AST to retrieve all functions from a valid script file or
scriptblock, then outputs them all. Useful for dot-sourcing
functions from a file that also contains running code.