Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
mbrownnycnyc / get-liveremoteprinters.ps1
Created March 12, 2015 12:50
Printer inventory function... Enumerates the registry (via powershell remoting) and gets a list of mapped printers for the currently logged on user, and their default printer. "cheap" because it just uses write-outpuit and tee, because I'm too lazy to comform to other methods. (note some comments are from when I was checking that all outlook pro…
function get-adusersid{
#http://community.spiceworks.com/how_to/show/2776-powershell-sid-to-user-and-user-to-sid
param(
[string]$domain,
[string]$user
)
$objUser = New-Object System.Security.Principal.NTAccount("$domain", "$user")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value
@mbrownnycnyc
mbrownnycnyc / gmusiccsv.py
Last active August 29, 2015 14:18
Quick gmusicapi to export all track titles from gmusic to a csv.
from gmusicapi import Mobileclient
api = Mobileclient()
api.login('[email protected]', 'AppSpecificPassword')
all_gmusic_tracks = api.get_all_songs()
len(all_gmusic_tracks)
import csv
#https://unofficial-google-music-api.readthedocs.org/en/latest/reference/mobileclient.html?highlight=track#gmusicapi.clients.Mobileclient.get_all_songs
with open('c:\gmusictracks.csv', 'wb') as myfile:
fieldnames = ['artist', 'album', 'title']
@mbrownnycnyc
mbrownnycnyc / get-folder.ps1
Created April 8, 2015 12:55
quick get-folder implementation
#http://blogs.technet.com/b/heyscriptingguy/archive/2013/08/03/weekend-scripter-use-powershell-to-get-folder-sizes.aspx
Function Get-FolderSize{
BEGIN{$fso = New-Object -comobject Scripting.FileSystemObject}
PROCESS{
$path = $args[0]
$folder = $fso.GetFolder($path)
$size = $folder.size
@mbrownnycnyc
mbrownnycnyc / redis_6379
Created April 27, 2015 14:08
redis chkconfig script... not systemd
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@mbrownnycnyc
mbrownnycnyc / decrypt_quarantined_files.bat
Created July 9, 2015 13:38
Quick decrypt script for quarantined files from Trend OfficeScan
@echo off
setlocal
if exist "C:\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\Admin\Utility\VSEncrypt" set PATH="C:\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\Admin\Utility\VSEncrypt";%PATH%
del /f /d "C:\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\Admin\Utility\VSEncrypt\VSEncrypt.log"
cd "C:\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\Virus"
dir /b
set /p filetarget="File to decrypt? "
copy %filetarget% %filetarget%_encrypted >NUL
VSEncode.exe -d /f %filetarget%
more "C:\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\Admin\Utility\VSEncrypt\VSEncrypt.log"
@mbrownnycnyc
mbrownnycnyc / get-localadmins.ps1
Created July 29, 2015 16:16
Very quick/raw script to get a list of members of local admin group in a resultant !! separated list
#--- Lists local users in local Administrators group: ---
((get-wmiobject Win32_GroupUser -computer $computername | `
where { `
( $_.GroupComponent -like '*Administrators*' ) `
-and
( $_.GroupComponent -notlike '*$((get-wmiobject win32_computersystem).domain.split('.')[0])*' ) `
-and `
( $_.PartComponent -like '*Win32_UserAccount*') `
-and `
(
wget http://list.iblocklist.com/?list=ydxerpxkpcfqjaybcssw&fileformat=p2p&archiveformat=gz
gunzip -c index.html* > level1.txt
ipset create LEVEL1 hash:ip hashsize 16777216 maxelem 16777216
awk '!x[$0]++' level1.txt | pg2ipset - - LEVEL1 | ipset restore
@mbrownnycnyc
mbrownnycnyc / iplookup.bas
Created September 4, 2015 13:37
The beginnings of an Excel macro for IP information
Public Function WhoIs(ByVal tRange As Range, ByVal tItem As String) As String
' http://www.mrexcel.com/forum/excel-questions/780655-doing-whois-excel.html
Dim xmlhttp As Object
Dim r, c As Integer
Dim t As String
r = tRange.Row
c = tRange.Column
ip = Cells(r, c).Text
@mbrownnycnyc
mbrownnycnyc / quicksqltest.ps1
Created September 16, 2015 16:10
quick SQL connectivity test with auth
#http://irisclasson.com/2013/10/16/how-do-i-query-a-sql-server-db-using-powershell-and-how-do-i-filter-format-and-output-to-a-file-stupid-question-251-255/
$connectionString = "Data Source=localhost\SQLEXPRESS;Integrated Security=false;Database=dbname;user id=sqluser;password=sqluserpassword;Connect Timeout=3;"
$sqlConn = new-object ("Data.SqlClient.SqlConnection") $connectionString
$sqlConn.Open()
$sqlcmd = New-Object System.Data.SqlClient.SqlCommand
$sqlcmd.connection = $sqlConn
$sqlcmd.commandtext = "SELECT * FROM information_schema.tables"
$sqlreader = $sqlcmd.ExecuteReader()
$table = new-object “System.Data.DataTable”
$table.Load($sqlreader)
#all taken from this kick ass post: https://p0w3rsh3ll.wordpress.com/2014/06/21/mount-and-dismount-volume-shadow-copies/
Function Mount-VolumeShadowCopy {
<#
.SYNOPSIS
Mount a volume shadow copy.
.DESCRIPTION
Mount a volume shadow copy.