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 / tasks.json
Last active May 23, 2017 21:55
I always end up with that one customer who wants me to email them the PS1 file. I've always hated having to do the manual copy and rename, so let's automate it until they get actual source control.
{
"version": "0.1.0",
"tasks": [
{
"taskName": "build",
"command": "powershell",
"args": [
"-ExecutionPolicy",
"Unrestricted",
"Merge-Script -Script '${file}' -Bundle -OutputPath '${fileDirname}\\out' -OutputType Script;",
function Export-Log {
<#
.Synopsis
Writes tab-separated log messages to a specified file.
.DESCRIPTION
Writes tab-separated log messages to a specified file.
.EXAMPLE
Export-Log -messagetype ERROR -logfile c:\temp\log.csv -message "Encountered error performing operation."
Will log an error message to the log located in c:\temp\log.csv
.EXAMPLE
@rodmhgl
rodmhgl / Create-PowerShellHere.ps1
Created January 9, 2017 16:55
Create PowerShell Here Right-Click Explorer Option
<#
.SYNOPSIS
Creates a right-click (or shift right-click) explorer menu option to open Powershell at the selected location
.DESCRIPTION
Creates a right-click (or shift right-click) explorer menu option to open Powershell at the selected location
.EXAMPLE
.\Create-PowerShellHere.ps1
Will create a right-click menu with the default text, "Open PowerShell Here"
.EXAMPLE
@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
@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 / jobdemo.ps1
Last active November 8, 2017 15:13
Quick PowerShell Jobs Demo
# functions.ps1 contains functions like Get-Services, Get-Process,
# Get-CustomFunction1, Get-CustomFunction2, etc. that execute
# locally on the remote computer. Output is ex
function Get-CustomFunction {
sleep 2
write-output $true
}
@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
}
$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 / 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 {
@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);