Skip to content

Instantly share code, notes, and snippets.

@jrwarwick
jrwarwick / Network_Domain_Recon.ps1
Last active August 25, 2016 22:42
Reconnaissance utility script which queries MSAD for computer objects with given name pattern, then discover if they are currently pingable, and if so, attempt to find out who is logged in.
$accumulatedList =''
foreach ($ws in dsquery computer -limit 1000 -name "*COMMON-NAME-FRAGMENT*" | dsget computer -samid | %{$_ -replace "\$",""}) {
$candidatehost = $ws.trim()
ping -n 2 $candidatehost
if ($LASTEXITCODE -eq 0) {
echo "##==-- TARGET UNIT ACTIVE! --------- $candidatehost --==##`a"
## this line only works on TServers ## query session /server:$candidatehost
try {
$userProc = gwmi win32_process -computer $candidatehost -filter "Name = 'explorer.exe'" -ErrorAction "Stop"
}
@jrwarwick
jrwarwick / du.ps1
Created August 25, 2016 17:03
In current working directory, list subfolders that contain at least 100MB in files.
Get-ChildItem -Force | Where-Object { $_.PSIsContainer } | ForEach-Object { $_.Name + ": " + "{0:N2}" -f ((Get-ChildItem $_ -Recurse | Measure-Object Length -Sum -ErrorAction SilentlyContinue).Sum / 1MB) + " MB" } | % { if ($_ -notmatch ': [0-9]{1,2}\.') {$_;}
@jrwarwick
jrwarwick / standard_logging.ps1
Created August 25, 2016 17:12
A quick, lean standard template for a PowerShell script that includes logging via start-transcript
## Standard informational header first.
##
## Configuration section next
$maxfoo = 10;
##
Start-Transcript -Path ".\$(([io.fileinfo]$MyInvocation.MyCommand.Definition).basename.Trim())_exec.log"
###### OR # "$($env:TEMP)\$(([io.fileinfo]$MyInvocation.MyCommand.Definition).basename.Trim())_exec.log"
###### OR # "$($env:LOGS)\$(([io.fileinfo]$MyInvocation.MyCommand.Definition).basename.Trim())_exec.log"
@jrwarwick
jrwarwick / VirtualAssistant.ps1
Last active October 14, 2021 19:57
DIY Virtual assistant uses TTS to read off a summary morning status report to you, if you schedule it with Windows Task Scheduler
#speech
$vox = New-Object -com SAPI.spvoice
$vox.speak("Testing testing 1 2 3")
#id knowledge
$vox.speak("Hello and welcome, $($env:username.substring(0,1)) $($env:username.substring(1))")
#time knowledge
$daysegments = @("Night","Morning","Morning","Afternoon","Evening","Night")
$curseg = [math]::Floor(((get-date -Uformat "%H") -5) / 4) + 1
#!Powershell
#Attempt to detect method of hashing/encrypting, focusing on the out-of-the-box .NET offerings
$messages = ('Create Enemy/Small Standard',
'create enemy/small standard',
'CREATE ENEMY/SMALL STANDARD',
'CreateEnemy/SmallStandard',
'Create Enemy/Small Standard ' ) #padded to 100 chars
$secret_keys = ('Artemis','artemis''ARTEMIS','2.4.0','eochu','EOCHU','techbear')
$hmac_classes = ('HMACMD5','HMACRIPEMD160','HMACSHA1','HMACSHA256','HMACSHA384','HMACSHA512')
@jrwarwick
jrwarwick / passphrase_gen_bash_alias.sh
Last active September 29, 2016 23:08
Ubuntu-oriented one-liner shell script to assist with new passphrase selection. With bonuses.
alias passphrasing="cat /usr/share/dict/words | random 10000 | grep '^[^A-Z]\{,8\}$' | sed \"s/'s$//\" | shuf -n 6 --random-source=/dev/random | xargs echo | sed 's/[^$]/\n/' | tee >( espeak --ipa ) >( sed '/^\s*$/d' | figlet -t -f tengwar ) | cat "
@jrwarwick
jrwarwick / test_row_generator.sql
Last active October 4, 2016 16:32
Row generator targeting an output size if exported to CSV
--Row generator query to give us a rougly n MB output to CSV, as specified in the first term of the connect by clause
--thanks to excellent inspiration and resource from Natalka Roshak, https://blogs.oracle.com/sql/entry/row_generators_part_2
select level, rownum,'zero_one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve_thirteen_fourteen_fifteen' number_names ,1234567890 ten_digit_number --about 115 bytes per row once csv'd
from dual
connect by level <= ( 80 * (1048576 / 112))
;
@jrwarwick
jrwarwick / SharePoint_Online_preamble_nuget_CSOM_SDK.ps1
Created November 7, 2017 19:08
PowerShell preamble to get nuget to get CSOM SDK so as to be able to authenticate to SharePoint Online from script
<# I have had a surprisingly hard time finding successful PowerShell interfaces to SharePoint online.
in lieu of a "pure" powershell replacement for the CSOM client (i.e., an import-module way rather than an SDK installation prerequisite)
I had pretty good luck with this "not so pure" (but still executable inside of same powershell script) preamble.
https://www.microsoft.com/en-us/download/details.aspx?id=42038
https://stackoverflow.com/questions/16657778/install-nuget-via-powershell-script
#>
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = "$rootPath\nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose
@jrwarwick
jrwarwick / demo_mutator.sh
Last active March 23, 2018 17:06
Simple virtual display via HTTP for Mycroft
#!/bin/bash
# Extremely low quality quick and dirty simulation of "dynamic data" feeding the mycroft httProjection.
# It does underscore how simple and easy and yet still pretty flexible this is, though.
pgrep -f 'python.*SimpleHTTPServer' || echo -e "the first thing you will want to do is start up the http service process with this command:\n\t python -m SimpleHTTPServer 8000 "
COUNTER=2
DORMANCY=2
until [ $COUNTER -lt 1 ]; do
@jrwarwick
jrwarwick / MSSQL_Backup.ps1
Created April 19, 2018 05:13
Basic MSSQL Backup
#!PowerShell
# Simple, basic localmachine MSSQL DB backup with no outage.
Start-Transcript -Path .\backup\MSSQL_Backup.log
get-date
write-output $env:COMPUTERNAME
Get-SqlDatabase -ServerInstance localhost |
Where { $_.Name -ne 'tempdb' } |
Backup-SqlDatabase -Verbose -BackupContainer .\backup\db\