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 / 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 / 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
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 / 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;",
@rodmhgl
rodmhgl / Get-GitTips.ps1
Last active June 30, 2017 22:14
Grabs a random tip from the Git-Tips Github repository
Function Get-GitTip {
<#
.SYNOPSIS
Grabs a random tip from the Git-Tips Github repository
.DESCRIPTION
Grabs a random tip from the Git-Tips Github repository
Designed to be used as part of my $profile to receive a daily tip
.PARAMETER URI
@rodmhgl
rodmhgl / Reset-Password.ps1
Last active July 12, 2017 23:41
For James Espinoza - Help Desk script to reset user's password
[cmdletbinding()]
param(
# Give the user the opton to user a -User command line parameter
[string]$User = $(Read-Host "Enter a samAccountName")
)
# Show $User details on console
# Consider which properties you actually need
# Using * is a memory hog and unnecesary
try {
@rodmhgl
rodmhgl / getSpace.ps1
Last active August 17, 2017 15:44
Just playing around
function getSpace {
[cmdletbinding()]
param(
[string]$space = ' ',
[string]$separator = '-',
[int]$depth
)
Write-Output $(($space + $separator) * $depth)
}
@rodmhgl
rodmhgl / Show-Blocks.ps1
Created November 7, 2017 00:58
Just demoing Begin, Process, End with some pseudo-code
Function Give-UserLicense ($User) {
#return $true
}
Function Add-UserLicenses {
param(
[Parameter(
Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
ValueFromPipeline = $true
)][String[]]$Username
$NetBiosName = "DOMAIN"
(Get-Acl c:\temp).Access |
Where-Object {
($_.IdentityReference -split '\\') -eq $NetBiosName
} |
ForEach-Object {
$SAMAccountName = ($_.IdentityReference -split '\\')[1]
$Class =( Get-ADObject -Filter {Samaccountname -eq $SAMAccountName}).objectclass
switch ($Class) {
@rodmhgl
rodmhgl / Invoke-PiHoleApi.ps1
Last active June 23, 2020 17:23
In-progress PowerShell interface to Pi-hole API - Tested with v3.2
Function Invoke-PiHoleApi {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
param(
[ValidateSet('type', 'version', 'summaryRaw', 'summary', 'overTimeData10mins', 'recentBlocked', 'topItems', 'getQuerySources', 'getForwardDestinations', 'getQueryTypes', 'getAllQueries', 'enable', 'disable')]
[String]$Method = 'summary',
[String]$Token = 'a67cc2dccc636ec92842101cc4de47a8c8132e6688415b8a2d7230c2142db2a6',
[String]$Address = '192.168.1.18'