Skip to content

Instantly share code, notes, and snippets.

View thedavecarroll's full-sized avatar
🧑‍💻
PowerShell Summit

Dave Carroll thedavecarroll

🧑‍💻
PowerShell Summit
View GitHub Profile
@thedavecarroll
thedavecarroll / Get-NetworkUsage.ps1
Last active May 13, 2020 05:17
IronScripter Challenge - April 27, 2020 - Building a Network Usage PowerShell Monitor
function Get-NetworkUsage {
[CmdletBinding(DefaultParameterSetName='Default')]
param(
[string]$ComputerName = $env:COMPUTERNAME,
[int]$WarnSentBytes = 10000,
[Parameter(ParameterSetName='Default')]
[int]$MaxSamples = 5,
[Parameter(ParameterSetName='Default')]
[int]$SampleInterval = 1,
[Parameter(ParameterSetName='Default')]
@thedavecarroll
thedavecarroll / ValidateTwoLetterRegionName.ps1
Created May 18, 2020 17:19
Validate Two Letter Region Names with PowerShell
$TwoLetterISORegionNames = Get-Culture -ListAvailable |
Foreach-Object {
try { [System.Globalization.RegionInfo]::new($_.Name) }
catch {}
} |
Select-Object -ExpandProperty TwoLetterISORegionName | Sort-Object -Unique
'US','CA','UK' | % { $_ -in $TwoLetterISORegionNames ? '{0} is valid' -f $_ : '{0} is not valid' -f $_ }
@thedavecarroll
thedavecarroll / OAuthParameters.class.ps1
Last active June 5, 2020 03:31
PowerShell 7 Class for OAuth 1
#requires -version 7.0
class OAuthParameters {
[string]$HttpMethod
[String]$BaseUri
[hashtable]$Query
[System.UriBuilder]$UriBuilder
[string]$UnescapedQueryString
[string]$EscapedQueryString
[object]$Body
@thedavecarroll
thedavecarroll / 1 - Get-IntermediateCountingChallenge .ps1
Created May 11, 2020 23:06
IronScripter Challenge - May 11, 2020 - A PowerShell Counting Challenge
# Intermediate Challenge
# Create a PowerShell function to get the sum and average of every X number between 1 and a user specified maximum
function Get-IntermediateCountingChallenge {
param(
[int]$Step,
[int]$Max
)
$NumberArray = for ($i = 1; $i -le $Max; $i = $i + $Step) { $i }
@thedavecarroll
thedavecarroll / 1-Measure-PSCodeLine.ps1
Last active June 24, 2020 14:35
IronScripter Challenge - June 9, 2020 - Building a PowerShell Command Inventory
function Measure-PSCodeLine {
[CmdLetBinding()]
param(
[Parameter(Mandatory,ValueFromPipeline)]
[ValidateScript({Test-Path -Path $_})]
[string]$Path
)
$TotalLines = $CodeLines = 0
$Files = Get-ChildItem -Path $Path -Recurse -Include *.ps1,*.psm1 -File
$Files | Foreach-Object {
@thedavecarroll
thedavecarroll / DemoModule.psd1
Last active July 26, 2020 16:58
PowerShell 7 Experimental Features Demo
@{
RootModule = 'DemoModule.psm1'
ModuleVersion = '0.7.0'
CompatiblePSEditions = 'Core'
GUID = 'a007643e-c876-4806-b6cb-367963716e98'
Author = 'Dave'
CompanyName = 'thedavecarroll'
@thedavecarroll
thedavecarroll / PracticeChallenge.ps1
Created February 1, 2021 15:50
Scripting Challenge Meetup
$Splatting = Get-Help about_Splatting
$SortByWordCount = $Splatting -Split('\W+') | Where-Object {$_ -ne 'the'} | Group-Object | Sort-Object -Property Count -Descending
$Splatting | Select-Object Name,
@{l='NumberOfWords';e={$_.ToString() | Measure-Object -Word | Select-Object -ExpandProperty Words}},
@{l='TopWord';e={$SortByWordCount[0].Name}},@{l='TopWordCount';e={$SortByWordCount[0].Count}},
@{l='Top5Words';e={($SortByWordCount.Name | Select-Object -First 5) -join ','}}
@thedavecarroll
thedavecarroll / 1-Intermediate.ps1
Last active February 16, 2021 00:27
Another PowerShell Math Challenge - IronScripter Challenge - 2021-02-09 (Intermediate Only)
#requires -Version 7
function Get-SumTotal {
[CmdLetBinding()]
param(
[Parameter(Mandatory,Position = 0,ValueFromPipeline)]
[ValidatePattern('^\d{1,10}$', ErrorMessage = '"{0}" does not match only numbers 0-9 with a maximum of 10.')]
#[ValidatePattern('^\d{1,10}$')]
#[ValidateScript({ if ($_ -notmatch '^\d{1,10}$') { throw ('{0}"{1}" does not match only numbers 0-9 with a maximum of 10.' -f [System.Environment]::NewLine,$_) } else { $true }})]
[string]$Value,
@thedavecarroll
thedavecarroll / PSChangeLogTools .psm1
Last active April 1, 2021 04:40
PSChangeLogTools script module which uses local git log, GitHub release, and GitHub issues to generate changelog updates
#Requires -Module PowerShellforGitHub
#Requires -Version 5.1
# GitLog Class
# class definition created by ConvertTo-ClassDefinition at 3/31/2021 9:47:01 PM for object type PSCustomObject
class PSGitLog {
[String]$CommitId
[String]$ShortCommitId
[DateTime]$AuthorDate
@thedavecarroll
thedavecarroll / Invoke-DiceRoll.ps1
Last active April 27, 2021 21:09
Simple Dice Roller, a la D&D
function Invoke-DiceRoll {
[Alias('idr','roll')]
[CmdletBinding()]
param(
[ValidatePattern(
'^(?:[1-9]|0[1-9]|1[0-9]|20)d(4|6|8|12|20|30|100)$',
ErrorMessage='Valid die types are d4,d6,d8,d10,d12,d20,d30,d100 rolled beteen 1 and 20 times. Your input was {0}. Please try again.'
)]
[string]$Roll = '2d6',
[switch]$Total