Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View rodmhgl's full-sized avatar
🐒
Just monkeyin' around

Rod Stewart rodmhgl

🐒
Just monkeyin' around
View GitHub Profile
@rodmhgl
rodmhgl / gist:cac3d84c2c918c81c1c1
Created July 7, 2014 13:06
Add Object to HashTable
# Courtesy of /u/LordZillion from /r/PowerShell
$Users = Import-Csv -Path C:\Temp\AllTheUsers.csv
$HashTable = @{}
Foreach($User in $Users) {
[int]$HashTableReference = $User.ExternalID
$HashTable[$HashTableReference] += New-Object -TypeName PSObject -Property @{
'UserName' = ($User.UserName);
'Password' = ($User.Password);
'Email' = ($User.Email);
@rodmhgl
rodmhgl / Get-STTinyURL
Created September 25, 2014 16:40
Get-STTinyURL
function Get-STTinyURL {
param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=0)
]
[String[]]$OriginalURL)
Process {
$OriginalURL | ForEach-Object {
$buttonStartJob_Click={
$buttonStartJob.Enabled = $false
#Create a New Job using the Job Tracker
Add-JobTracker -Name "JobName" `
-JobScript {
#--------------------------------------------------
#TODO: Set a script block
#Important: Do not access form controls from this script block.
@rodmhgl
rodmhgl / gist:19a188c7f48848ed35f2
Last active September 17, 2015 02:05
Rename Student Names to IDs
Function Create-HashTable {
param ($filePath)
$mytable = Import-Csv -Path $filePath
$HashTable=@{}
foreach($r in $mytable)
{
$HashTable[$r.Name] = $r.ID
}
return $HashTable
}
@rodmhgl
rodmhgl / Get-SAMAccountName
Created June 28, 2013 19:15
PowerShell snippet - requires Quest AD Tools - will search Active Directory for the given Display Name, and return the samaccountname, display name, office, and telephone number for matching users
function Get-SamAccountName {
param ($DisplayName)
Get-QADUser -DisplayName "*$DisplayName*" | select samaccountname, displayname, office, telephonenumber
}
@rodmhgl
rodmhgl / Get-RealName
Created June 28, 2013 19:19
PowerShell - Searches Active Directory for a given SAMAccountName, returns SAMAccountName, displayname, office, telephonenumber
function Get-RealName {
param ($SAMAccountName)
Get-QADUser -SamAccountName $SAMAccountName | select samaccountname, displayname, office, telephonenumber
}
@rodmhgl
rodmhgl / Reset-RDPListener
Created June 28, 2013 20:02
Attempts to reset the RDP listener of a remote server. Sometimes it works, sometimes it doesn't, but it's always worth a shot.
function Reset-RDPListener {
param($ComputerName)
$ts = Get-WMIObject -class win32_Terminalservicesetting -comp $ComputerName
$ts.SetAllowTSConnections($false)
$ts.SetAllowTSConnections($true)
}
@rodmhgl
rodmhgl / DC_Regex
Created October 22, 2013 16:13
Regex, extract DC from DN
$DN = 'CN=Username,OU=OrganizationalUnit,DC=lab,DC=local'
$pattern = '(?i)DC=\w{1,}?\b'
([RegEx]::Matches($DN, $pattern) | ForEach-Object { $_.Value }) -join ','
@rodmhgl
rodmhgl / Get-RSFileHash.ps1
Last active November 17, 2016 21:16
Just looking to get input on the best way to handle parameter sets
function Get-RSFileHash {
<#
.Synopsis
Returns an MD5 filehash when given a file path
.DESCRIPTION
Returns an MD5 filehash when given a file path
.EXAMPLE
Get-RSFileHash -Filename c:\temp\filetohash.txt
.EXAMPLE
Get-ChildItem c:\temp\*.txt | get-rsfilehash
@rodmhgl
rodmhgl / temp.ps1
Last active December 15, 2016 00:05
Why is remoting slower than running over the network?
# Remote Code
$SB = {
param($file)
$SHA1 = New-Object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
$stream = [System.io.file]::Open($file, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
$hash = [System.BitConverter]::ToString($SHA1.ComputeHash($stream))
$hash = $hash.replace('-','')
$hash = "0x$hash"
$stream.Close()
return $hash