Skip to content

Instantly share code, notes, and snippets.

@bohack
bohack / PowerShell Find Last Logon Time
Created October 31, 2017 14:10
PowerShell Find Last Logon Time
Import-Module ActiveDirectory
function Get-ADUserLastLogon([string]$userName)
{
$dcs = Get-ADDomainController -Filter {Name -like "*"}
$time = 0
foreach($dc in $dcs)
{
$hostname = $dc.HostName
$user = Get-ADUser $userName | Get-ADObject -Properties lastLogon
@bohack
bohack / Create Users and Groups for Lab
Created November 6, 2017 19:28
Create Users and Groups for Lab
# Create users and Groups for Lab
# Bohack
# 08/31/14
Import-Module ActiveDirectory
# Create the OU structure
Echo "Creating OU Structure"
New-ADOrganizationalUnit -Name Contoso -Path "DC=Contoso,DC=Com"
@bohack
bohack / Create Users for Lab Redux
Last active November 6, 2017 20:22
Create Users for Lab Redux
# Create users and Groups for Lab
# Bohack
# 11/6/17
Import-Module ActiveDirectory
# Variables for Creation
$rtdomain = "DC=Netmind,DC=Local"
$orgrt = "Netmind"
$orgpath = "OU=Netmind,$rtdomain"
@bohack
bohack / Secure Local Password Check
Created December 6, 2017 15:25
Secure Local Password Check
<#
.Synopsis
Verify Local SAM store
.DESCRIPTION
This function takes a user name and a password as input and will verify if the combination is correct. The function returns a boolean based on the result. The script defaults to local user accounts, but a remote computername can be specified in the -ComputerName parameter.
.NOTES
Name: Test-LocalCredential
Author: Jaap Brasser
@bohack
bohack / Get Total RAM from a PC via VBscript WMI
Created January 30, 2018 14:44
Get Total RAM from a PC via VBscript WMI
On Error Resume Next
Prefix ="fstu516"
For Count = 1 to 36
Total = 0
If Count < 10 then Fill="00"
If Count < 100 and Count > 9 then Fill="0"
strComputer = Prefix & Fill & Count
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")
@bohack
bohack / Get a list of users by their SAMid and lookup their UPN
Created February 23, 2018 18:07
Get a list of users by their SAMid and lookup their UPN
@ECHO OFF
REM Bohack
REM 2/23/18
REM Get a list of users by their SAMid and lookup their UPN
FOR /F "TOKENS=*" %%a IN (listofusers.txt) DO (
ECHO %%a
DSQUERY USER -SAMID %%a | DSGET USER -SAMID -UPN
)
@bohack
bohack / VDI Printer Script
Created March 20, 2018 16:33
VDI Printer Script
' Author: Jon Buhagiar
' Date: 10/19/17
' Purpose: This script will check the ViewClient_Broker_Tags. If it is External
' or 10.8x.0.0 (wireless) then it will quit and allow TPAutoConnect to
' redirect the client host default printer. If it is not External or 10.8x
' it is assumed to be Internal, the script will then record the current
' default printer and set the default printer via the regKey. Edit the
' strIPExclude with a CSV value.
'
' Usage: Use a GPO applied to the VDI computers for logon and logoff scripts for
@bohack
bohack / PacketFence Code Generator
Created August 21, 2018 13:34
PacketFence Code Generator
#!/bin/bash
# Bohack
# 04/26/16
# Script to generate password for htpasswd file
if [ -z "$1" ]
then
echo
echo "$0 [user to generate passwd for]"
@bohack
bohack / Nexus ACL Objects Example
Created August 30, 2018 15:55
Nexus ACL Objects Example
object-group ip address test_hosts
host 10.10.1.151
host 10.10.1.181
object-group ip port test_ports
eq 5000
ip access-list IT-Acad-VDC
permit tcp 172.16.0.0/12 addrgroup test_hosts portgroup test_ports
@bohack
bohack / Deployment Script for TFS to PHP
Created September 11, 2018 16:00
Deployment Script for TFS to PHP
#!/bin/bash
DEPLOYPATH="/var/www/websitea/"
filename=$DEPLOYPATH'rwpermissions.txt'
echo Start
while read p; do
echo runner=$DEPLOYPATH$p
runner=$DEPLOYPATH${p/$'\r'/}
chmod -R 0666 $runner
chcon -v -R --type=httpd_sys_rw_content_t $runner