Skip to content

Instantly share code, notes, and snippets.

View sdwheeler's full-sized avatar
🖥️
Marking down

Sean Wheeler sdwheeler

🖥️
Marking down
View GitHub Profile
@sdwheeler
sdwheeler / parse-netstat.ps1
Created September 29, 2021 00:05
Example for parsing the output from netstat
function parseNetstat {
param([object[]]$Lines)
if ($IsWindows) {
$skip = 4
} else {
$skip = 3
}
$Lines | Select-Object -Skip $skip | ForEach-Object {
function New-DevOpsWorkItem {
param(
[Parameter(Mandatory=$true)]
[string]$title,
[Parameter(Mandatory=$true)]
[string]$description,
[int]$parentId,
@sdwheeler
sdwheeler / cards.ps1
Last active October 2, 2021 08:43
Poker hand example using Update-List
class Cards {
[System.Collections.Generic.List[string]]$cards
[string]$name
Cards([string]$_name) {
$this.name = $_name
$this.cards = [System.Collections.Generic.List[string]]::new()
}
NewDeck() {
@sdwheeler
sdwheeler / show-redirects.ps1
Last active November 16, 2022 23:58
Script to show each step of a redirection chain
param(
[string]$startURL,
[switch]$showall
)
$ErrorActionPreference = 'Stop'
$Error.Clear()
$lastError = $null
function getUrl {
function Get-FileEncoding {
## Get-FileEncoding http://poshcode.org/2153
<#
.SYNOPSIS
Gets the encoding of a file
.EXAMPLE
function get-logonevents {
param(
[string]$computer=$env:computername,
[int]$days = 30
)
$millisecperday = 24*60*60*1000
$logonType = @{
2='Interactive';
3='Network';
4='Batch';
#region AD Functions
#-------------------------------------------------------
function get-servers {
param([string[]]$names,
[string[]]$props = @('DNSHostName','OperatingSystem')
)
foreach ($name in $names) {
$c = $null
$hostname = ($name -split '\.')[0]
@sdwheeler
sdwheeler / grab-url.ps1
Created October 8, 2016 21:37
Use powshell to download a file
function grab-url {
param(
[string[]]$filelist,
$headers,
[switch]$force
)
$curdir = (get-location).path
$wc = New-Object System.Net.WebClient
if ($headers) {
foreach ($key in $headers.keys) {
@sdwheeler
sdwheeler / woot.ps1
Created October 8, 2016 21:34
Examples of accessing woot.com from a PowerShell scrip
function woot {
param([ValidateSet('accessories','computers','electronics','home','kids','sellout','shirt','sport','tools','wine','www', ignorecase=$true)]
[string]$site
)
$url = 'http://api.woot.com/1/sales/current.rss'
if ($site -ne "") {
$url = "http://api.woot.com/1/sales/current.rss/{0}.woot.com" -f $site
}
$woots = Invoke-RestMethod $url
foreach ($woot in $woots) {
@sdwheeler
sdwheeler / update-sysinternals.ps1
Created October 8, 2016 21:29
Download the latest version of the sysinternals tools
function update-sysinternals {
param([switch]$exclusions=$false)
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $identity
if($principal.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$web = get-service webclient
if ($web.status -ne "Running") { "Starting webclient..."; start-service webclient }
$web = get-service webclient
while ($web.status -ne "Running") { sleep -sec 1 }
if ($exclusions) {